Master C Programming with 50 free flashcards. Study using spaced repetition and focus mode for effective learning in Programming.
A pointer is a variable that stores the memory address of another variable.
Declared using the * operator: int *ptr;
The address-of operator & retrieves a variable's address: ptr = &x;
Dereferencing means accessing the value stored at the address a pointer holds.
Use the * operator: int val = *ptr;
This retrieves the value at the memory location pointed to by ptr.
A NULL pointer is a pointer that does not point to any valid memory location.
Assigned with: int *ptr = NULL;
Always check for NULL before dereferencing to avoid segmentation faults.
malloc() allocates a block of memory on the heap and returns a pointer to it.
Syntax: int *p = (int *)malloc(n * sizeof(int));
Returns NULL if allocation fails. Memory is uninitialized.
malloc(size) allocates uninitialized memory of the given sizecalloc(count, size) allocates memory for an array of count elements, each of size bytes, and initializes all bits to zero
Calling free(ptr) releases dynamically allocated memory back to the system.
Failing to free causes a memory leak, where allocated memory is never reclaimed.
After freeing, set the pointer to NULL to avoid dangling pointer issues.
A dangling pointer points to memory that has been freed or deallocated.
Dereferencing it causes undefined behavior.
Prevention: set pointers to NULL after calling free().
A struct (structure) groups related variables of different types under one name.
Example:struct Point { int x; int y; };
Access members with the dot operator: p.x or arrow operator for pointers: ptr->x
Use malloc() with sizeof:struct Point *p = (struct Point *)malloc(sizeof(struct Point));
Access members via the arrow operator: p->x = 10;
Remember to free(p) when done.
A union is like a struct, but all members share the same memory location.
The size of a union equals the size of its largest member.union Data { int i; float f; char c; };
Only one member can hold a value at a time.
Struct: each member has its own memory; size is the sum of all members (plus padding)Union: all members share the same memory; size equals the largest memberStructs store multiple values simultaneously; unions store only one at a time.
An enum (enumeration) defines a set of named integer constants.enum Color { RED, GREEN, BLUE };
By default, values start at 0 and increment by 1.
You can assign custom values: enum Color { RED = 1, GREEN = 5 };
Flashcards
Flip to reveal
Focus Mode
Spaced repetition
Multiple Choice
Test your knowledge
Type Answer
Active recall
Learn Mode
Multi-round mastery
Match Game
Memory challenge