Pointers, Dynamic Memory, Linked Lists, and File I/O Flashcards
(40 cards)
What is pointer arithmetic?
Performing arithmetic operations on pointers.
Fill in the blank: A void pointer (void *) is a _______.
Generic pointer that can store addresses of any data type.
What function is used for dynamic memory allocation?
malloc()
What should you always check after using malloc()?
If malloc() succeeds.
What function is used to release allocated memory?
free()
What are common pitfalls related to pointers?
- Memory Leaks
- Dangling Pointers
- Wild Pointers
What is a segmentation fault?
Occurs when trying to access memory illegally.
What tool can be used for memory debugging?
valgrind
True or False: Pointer arithmetic follows the size of the data type.
True.
What happens if you forget to free memory?
Memory leaks occur.
What is a dangling pointer?
Using a pointer after the memory it points to has been freed.
What is a wild pointer?
Using uninitialized pointers.
What does p++ do if p is a pointer to an int?
Moves p to the next int (increases by sizeof(int)).
What happens when you write beyond allocated space?
It can corrupt adjacent memory.
What is the output of printf(“p = %p, *p = %c\n”, p, *p) if p points to ‘A’?
p= 0x1e224eff, *p= A
Fill in the blank: The function _______ is used to allocate memory for an array of integers.
malloc()
What is Pass by Value?
A copy of the variable is passed to the function, keeping the original variable unchanged.
What is a downside of Pass by Value?
Can be inefficient for large data structures.
How does Pass by Reference work?
A pointer to the variable is passed instead of a copy, allowing the original variable to be modified.
What is a pointer in C?
A pointer stores the memory address of another variable.
What is the syntax to dereference a pointer?
Using the asterisk (*) before the pointer variable.
What is a function pointer?
A function pointer stores the address of a function.
Why use function pointers?
Makes code modular and reusable; enables dynamic function execution.
What is a key advantage of linked lists over arrays?
They do not need a predefined size and allow efficient insertions and deletions.