Test yourself under real exam conditions: 50 timed questions, 60 on the clock, pass mark 70%%. Instant score with a full review of everything you got wrong. Free — no account needed.
Exam details
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