Q: What character marks the end of a string in C?
A: '\0'
Q: What keyword is used to define a struct?
A: struct
Q: What operator gives the address of a variable?
A: &
Q: What function is used to open a file?
A: fopen()
Q: What function is used to allocate memory dynamically?
A: malloc()
Q: What does strlen("Hello") return?
A: 5
Q: What operator is used to access struct members?
A: .
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
Q: What are the two modes you need to know for opening files?
A: "r" and "w"
Q: What does calloc() do differently than malloc()?
A: Calloc() initializes memory to zero
Q: Why can scanf("%s", str) be unsafe?
A: It can cause buffer overflow and stops at spaces
Q: How do you access a struct member through a pointer?
A: Using ->
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
Q: What happens if you open a file in "w" mode and it already exists?
A: It is overwritten
Q: What function is used to free allocated memory?
A: free()
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())
Q: What are structs used for in C?
A: Grouping related variables of different types
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
Q: What do argc and argv represent?
A: Number of arguments and array of argument strings
Q: What is the difference between stack and heap memory?
A: Stack is automatic/local; heap is manually allocated (dynamic)
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
Q: What is the difference between using . and -> when accessing struct members?
A: . is used with struct variables; -> is used with pointers to structs
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
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
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