C_Language_Notes (1)
C_Language_Notes (1)
1. Introduction to C
C is like the 'assembly line' of programming languages, designed to give you control and
efficiency, perfect for building the operating systems and complex programs that many
higher-level languages depend on.
- Developed by Dennis Ritchie in 1972.
- General-purpose, procedural, and efficient.
- Offers low-level memory access and is widely used for system programming.
2. Structure of a C Program
A C program is like a blueprint, where each element has a specific role:
- Header files bring in tools and predefined functions, like a toolbox.
- The main function, `main()`, is the starting point for your program.
- Each line of code ends with a semicolon, just like each instruction in a manual needs a clear
ending.
3. Data Types
Think of data types as containers with specific shapes for holding different values:
- `int`: Integer numbers, similar to whole-number markers.
- `float`: Real numbers, perfect for fractions.
- `double`: Precision numbers for detailed measurements.
- `char`: Single characters, like letters in a word.
- Derived types like arrays and pointers are containers holding multiple items or addresses.
5. Operators
Operators act like tools:
- Arithmetic operators (`+`, `-`, etc.) perform basic math.
- Logical operators (`&&`, `||`) evaluate true/false conditions.
- Assignment operators (`=`, `+=`) set or update values.
8. Functions
Functions are mini-programs or 'helpers':
- Define them with `return_type function_name(parameters) { code }`
- They can be called anytime and help avoid repetitive code.
9. Arrays
Arrays are like shelves, holding multiple values of the same type in an organized manner:
- Single-dimensional arrays hold one row of values.
- Multi-dimensional arrays, like matrices, hold values in rows and columns.
10. Strings
Strings are arrays of characters that represent words or phrases, with a null `\0` character
at the end.
- C provides functions for managing strings: `strcpy`, `strcat`, `strlen`, `strcmp`.
11. Pointers
Pointers are like addresses on a map pointing to the location of a variable in memory:
- `*` dereferences the pointer, accessing the value at the address.
- `&` is used to find the address of a variable.
12. Structures
Structures are like custom boxes that hold different types of data in a single unit:
- Defined with `struct`, they combine different data types.
- You can access members with the `.` operator.
13. Unions
Unions are like shared lockers; they store one value at a time:
- Memory is shared by all members, meaning only one can be stored at a time.