Study guide: C Language Fundamentals

Course Outline

  1. C Language Origins and Uses
  2. C Program Structure
  3. Data Types and Variables
  4. C Operators and Precedence
  5. Programming Errors and Debugging
  6. Compilation and Program Execution
  7. C Storage Classes
  8. C Language History

1. C Language Origins and Uses

★ Must-know

  • In 1972, Dennis Ritchie developed C at Bell Laboratories to write the UNIX operating system.

  • C is an imperative, procedural, general-purpose programming language.

Further detail

  • C is strongly associated with UNIX because it was developed to write that operating system.

  • C is used to develop operating systems, databases, and embedded systems.

  • The course describes C as structured, relatively easy to learn, efficient, suitable for low-level activities, and compilable on various computer platforms.

2. C Program Structure

★ Must-know

  • The six sections of a C program are:

    • documentation
    • preprocessor directives
    • definitions
    • global declarations
    • the main function
    • user-defined functions
  • The preprocessor directive #include incorporates a specified file so its contents are compiled with the function being compiled.

  • The main function is required in a C program and is the first function executed by the computer.

Further detail

  • The documentation section gives an overview of a program, such as its name, date, description, and title, and does not interfere with the code.

  • The header file stdio.h provides definitions for stdin, stdout, and stderr, while math.h is used for mathematical functions.

📌 Local declarations define variables inside a function or block, while global declarations are made in the program's global section.

  • A return statement ends function execution and returns control to the calling function; it returns a value when the function's return type is not void.

Memory Hook

A program moves from documentation and preprocessing to declarations, main, and user-defined functions.

3. Data Types and Variables

Key Concepts & Definitions

  • Data type: Specifies what kind of value a variable can store, the memory it requires, and the operations that can be performed on it.
  • Variable: A named container for storing a data value.

★ Must-know

📌 C variable names must be unique, begin with a letter or underscore, and contain only letters, digits, or underscores; they are case-sensitive, cannot contain spaces or special characters, and cannot be reserved words.

Further detail

  • C data types are classified as:

    • primitive
    • void
    • user-defined
    • derived
  • Arithmetic primitive data types include integer and floating-point types, while void has no value and provides no result to its caller.

  • The listed sizes are char 1 byte, float 4 bytes, and int 4 bytes.

  • The course lists short int as 2 bytes with range -32,768 to 32,767 and format specifier %hd.

  • The course lists float as 4 bytes with range 1.2E-38 to 3.4E+38 and format specifier %f.

Memory Hook

Primitive types store values directly; derived types come from primitive or built-in types.

4. C Operators and Precedence

★ Must-know

  • C operators are grouped as:
    • arithmetic
    • relational
    • logical
    • bitwise
    • assignment
    • miscellaneous

📌 Relational operators compare values, while logical operators combine or reverse logical conditions.

  • Operator precedence determines how an expression is grouped and evaluated, with higher-precedence operators evaluated first.

Further detail

  • Arithmetic operators include:

    • addition
    • subtraction
    • multiplication
    • division
    • modulus
    • increment
    • decrement
  • Bitwise operators act on individual bits; for example, with A = 60 and B = 13, A & B = 12, A | B = 61, and A ^ B = 49.

  • The sizeof operator returns the size of a variable, the unary & operator returns its address, and the unary * operator dereferences a pointer to a variable.

  • In x = 7 + 3 * 2, multiplication precedes addition, so x is assigned 13 rather than 20.

5. Programming Errors and Debugging

Key Concepts & Definitions

  • Debugging: The process of removing bugs or faults from a program.

★ Must-know

  • The five listed types of C programming errors are:
    • syntax
    • run-time
    • linker
    • logical
    • semantic

📌 Syntax errors violate language syntax and are detected during compilation, whereas run-time errors occur during execution after successful compilation.

Further detail

  • Division by zero is a common cause of a run-time error.

📌 A linker error prevents creation of the executable, while a logical error produces incorrect output despite the program being error-free in the compiler's sense.

  • Semantic errors include:
    • using an uninitialized variable
    • incompatible types
    • invalid expressions
    • an array index out of bounds

6. Compilation and Program Execution

Essential Points

  • A C compiler converts a program into machine-readable object files, and a linker combines object files into a single executable file.

7. C Storage Classes

★ Must-know

  • The four storage classes in C are:

    • auto
    • register
    • static
    • extern
  • A static local variable retains its value between function calls and exists for the lifetime of the program.

📌 The extern storage class refers to a global variable or function defined elsewhere; an extern variable declaration cannot initialize the variable.

Further detail

  • The auto storage class is the default for local variables and can be used only within functions.

📌 The register storage class suggests storing a local variable in a register, but its actual use depends on hardware and implementation restrictions.

  • Applying static to a global variable restricts its scope to the file in which it is declared.

Memory Hook

Static locals persist across calls, while extern refers to a global defined elsewhere.

8. C Language History

Essential Points

  • In 1989, ANSI formalized the C language. - ANSI (American National Standard Institute), 1988

  • C succeeded B and inherited features from B and BCPL.

  • The listed languages developed before C are ALGOL (1960), BCPL (1967), B (1970), Traditional C (1972), K&R C (1978), ANSI C (1989), ANSI/ISO C (1990), and C99 (1999).

  • The listed developers or committees are:

    • the International Group for ALGOL
    • Martin Richards for BCPL
    • Ken Thompson for B
    • Dennis Ritchie for Traditional C
    • Kernighan and Ritchie for K&R C
    • the ANSI Committee for ANSI C
    • the ISO Committee for ANSI/ISO C
    • the Standardization Committee for C99

Test yourself

Take a 7-question practice quiz on C Language Fundamentals, with every answer explained.

1. Which description best identifies the C programming language?

2. Which function is required in a C program and executed first?

Take the quiz →

Study with flashcards

Memorize the key concepts of C Language Fundamentals with 10 flashcards.

Who developed C at Bell Laboratories in 1972, and to write which operating system?

Dennis Ritchie developed C to write UNIX.

What six sections make up a C program?

Documentation, preprocessor directives, definitions, global declarations, the main function, and user-defined functions.

Which four purposes is C used for?

Operating systems, databases, embedded systems, and low-level activities.

See the flashcards →

Related classes

Make your own study guides

Upload your class notes and Revizly writes a study guide, a quiz and flashcards in about a minute.

Study guide maker