C Programming Summary: Arrays, Pointers, and Structures
1. Arrays
- Fixed-size collection of elements of the same type.
- Declared as: int arr[5];
- Initialized as: int arr[3] = {1, 2, 3};
- Accessed by index: arr[0], arr[i]
- Multidimensional: int matrix[2][3];
- Passed to functions as a pointer to the first element.
2. Pointers
- Stores the memory address of another variable.
- Declared as: int *p;
- Assigned using address-of: p = &x;
- Dereferenced with *p to access or modify value.
- Used with arrays, dynamic memory, and function arguments.
- Dynamic memory: malloc, calloc, free.
3. Structures
- Custom user-defined data type grouping multiple variables.
- Declared as:
struct Person {
char name[20];
int age;
};
- Accessed with dot operator: p.age
- Pointer to struct uses -> operator: ptr->age
- Can be nested and used in arrays or functions.