Strings
Structs
Pointers
Files
Memory
100

Q: What character marks the end of a string in C?

A: '\0'

100

Q: What keyword is used to define a struct?

A: struct

100

Q: What operator gives the address of a variable?
 

A: &

100

Q: What function is used to open a file?

A: fopen()

100

Q: What function is used to allocate memory dynamically?

A: malloc()

200

Q: What does strlen("Hello") return?

A: 5

200

Q: What operator is used to access struct members?

A: .

200

Q: Why must a pointer be initialized before it is used?

A: Because an uninitialized pointer may point to an unknown memory location, causing undefined behavior

200

Q: What are the two modes you need to know for opening files?

A: "r" and "w"

200

Q: What does calloc() do differently than malloc()?

A: Calloc() initializes memory to zero

300

Q: Why can scanf("%s", str) be unsafe?

A: It can cause buffer overflow and stops at spaces

300

Q: How do you access a struct member through a pointer?

A: Using ->

300

Q: What would happen if you forgot to dereference a pointer when trying to modify a value inside a function?

A: You would modify the pointer itself instead of the value it points to

300

Q: What happens if you open a file in "w" mode and it already exists?

A: It is overwritten

300

Q: What function is used to free allocated memory?

A: free()

400

Q: Why does assigning one string array to another using = not work in C?  

A: Because arrays cannot be assigned directly; you must copy each character (e.g., using strcpy())

400

Q: What are structs used for in C?

A: Grouping related variables of different types

400

Q: Explain how a pointer can be used to modify a variable without directly accessing that variable by name.

A: By storing the variable’s address in the pointer and using dereferencing (*pointer) to change the value at that memory location

400

Q: What do argc and argv represent?

A: Number of arguments and array of argument strings

400

Q: What is the difference between stack and heap memory?

A: Stack is automatic/local; heap is manually allocated (dynamic)

500

Q: Why is it dangerous to use functions like strlen() or printf("%s") on a character array that is not properly null-terminated?

A: Because they will read past memory until a '\0' is found, causing undefined behavior

500

Q: What is the difference between using . and -> when accessing struct members?

A: . is used with struct variables; -> is used with pointers to structs

500

Q: What is the difference between modifying a pointer itself and modifying the value it points to?

A: Changing the pointer changes the address it stores; dereferencing (*p) changes the actual value at that address

500

Q: Why is checking if a file pointer is NULL after fopen() critical before reading or writing?

A: Because operations on a NULL pointer will cause runtime errors or crashes

500

Q. What is the difference between a memory leak and a dangling pointer?

A: Memory leak = lost reference to allocated memory; dangling pointer = pointer still exists but memory was freed