'\0' (the null terminator)
The program reads beyond the intended memory, causing undefined behavior or memory corruption.
It gives the memory address of a variable.
In C, how do you simulate pass-by-reference?
By passing the variable’s address using pointers.
What are the two file modes you need to know for this exam?
"r" for reading and "w" for writing.
What is the key difference between malloc() and calloc()?
calloc() initializes memory to zero; malloc() leaves memory uninitialized.
Which function returns the number of characters in a C string, excluding the null terminator?
strlen()
What does the asterisk (*) operator do when used on a pointer?
It dereferences the pointer to access or change the value stored at that address.
Why do we pass arrays to functions without needing the & operator?
Array names already act as pointers to their first element.
What do argc and argv represent?
argc: argument count
argv: argument vector (array of strings passed from command line)
What function is used to return dynamically allocated memory back to the system?
free()
Why is using scanf("%s", str); dangerous when reading strings?
It can cause buffer overflow because it does not limit input size.
Given int *p; how do you make p point to variable x?
p = &x;
What happens if you pass a pointer to a function but forget to dereference it inside the function?
The function will not modify the original variable’s value.
What does fopen() return if it fails?
NULL
What is a memory leak?
Allocated memory that is never freed and becomes inaccessible.
What is the difference between fgets() and scanf("%s") when reading strings?
fgets() reads entire lines (including spaces) safely; scanf("%s") stops at whitespace and risks overflow.
What is the difference between a pointer variable and the value it points to?
The pointer stores a memory address; the dereferenced pointer (*p) accesses the value stored at that address.
Explain why void update(int x) cannot change the original x, but void update(int *x) can.
The first receives a copy (pass-by-value); the second receives the address (pass-by-reference).
Explain why you should always use fclose() on a file pointer.
To ensure data is written properly and system resources are released
What is the purpose of using a struct in C?
To group related variables of different types under one name.
Explain what happens when you forget to include the null terminator '\0' in a string.
The program reads beyond the intended memory, causing undefined behavior or memory corruption.
Why must dynamically allocated pointers eventually be freed?
To avoid memory leaks and return memory to the system.
What is the difference between passing a pointer and passing a pointer to a pointer?
Passing a pointer modifies the value at the address; passing a pointer-to-pointer allows modifying the pointer itself.
Why is command-line input (argc/argv) useful for file-processing programs?
It allows users to specify filenames or parameters at runtime instead of hardcoding them.
Why is it essential to use sizeof() when dynamically allocating memory?
To ensure the correct amount of memory is allocated for the data type.