Strings & Characters
Pointers
Pass by Reference
File Input & Command Line
Dynamic Memory & Structs
100
What character always marks the end of a C string?

'\0' (the null terminator)

100

The program reads beyond the intended memory, causing undefined behavior or memory corruption.

It gives the memory address of a variable.

100

In C, how do you simulate pass-by-reference?

By passing the variable’s address using pointers.


100

What are the two file modes you need to know for this exam?

"r" for reading and "w" for writing.

100

What is the key difference between malloc() and calloc()?

calloc() initializes memory to zero; malloc() leaves memory uninitialized.

200

Which function returns the number of characters in a C string, excluding the null terminator?

strlen()

200

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.

200

Why do we pass arrays to functions without needing the & operator?

Array names already act as pointers to their first element.

200

What do argc and argv represent?

argc: argument count

argv: argument vector (array of strings passed from command line)

200

What function is used to return dynamically allocated memory back to the system?

free()

300

Why is using scanf("%s", str); dangerous when reading strings?

It can cause buffer overflow because it does not limit input size.

300

Given int *p; how do you make p point to variable x?

p = &x;

300

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.

300

What does fopen() return if it fails?

NULL

300

What is a memory leak?

Allocated memory that is never freed and becomes inaccessible.


400

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.

400

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.

400

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).


400

Explain why you should always use fclose() on a file pointer.

To ensure data is written properly and system resources are released

400

What is the purpose of using a struct in C?

To group related variables of different types under one name.

500

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.

500

Why must dynamically allocated pointers eventually be freed?

To avoid memory leaks and return memory to the system.

500

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.

500

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.

500

Why is it essential to use sizeof() when dynamically allocating memory?

To ensure the correct amount of memory is allocated for the data type.