C Basics
Memory Management
File Operations
Data Structures
Misc
100

List the different modes of checking file permissions using the access() function in C.

 R_OK to check read permission, W_OK for write permission, and F_OK to check if the file exists.

100

What does the malloc function do?

malloc allocates a specified amount of memory and returns a pointer to the beginning of that block.

100

True or False: fopen() will create a file if it does not exist when using mode "r".

 False. Using "r" mode with fopen() will fail if the file does not exist.

100

What is a struct in C, and why do we use them?

Struct in C is a user-defined data type that allows to combine data items of different kinds.

100

True or False: Recursion is always a better choice than iteration.

 False. Recursion is not always better than iteration; it can be less efficient and more memory-intensive depending on the context.

200

What is the output of the following C code? printf("%d", 5==5);

1

200

 True or False: Memory allocated with malloc must be deallocated with free

True

200

What function would you use to write formatted output to a file?

The function fprintf() is used to write formatted output to a file.

200

Describe the difference between little endian and big endian.

In big endian format, the most significant byte (MSB) of the data is stored at the smallest memory address. In little endian format, the least significant byte (LSB) of the data is stored at the smallest memory address. 

200

What is a segmentation fault?

A segmentation fault is an error caused by accessing memory that the program does not have permission to access.

300

What is the purpose of the function prototype?


They are used to help compilers understand how to handle function calls.

300

What will happen if you try to access memory that has been freed? How can you prevent this?

Attempting to access freed memory can lead to undefined behavior, including program crashes or data corruption. Set it to Null after freeing it.

300

Explain the use of feof() in file handling.

feof() checks if the end of a file has been reached.

300

Describe the difference between a union and a struct.

The most significant difference is in memory usage. structs allocate enough space to store all members, while unions use the same space for all its members.

300

Explain what the static keyword does when it's used with a variable inside a function.

The static keyword when used inside a function makes the variable retain its value between function calls and restricts its scope to within the function.

400

 What does the volatile keyword do?

The volatile keyword tells the compiler that a variable's value may change at any time, preventing the compiler from optimizing out necessary loads and stores around the variable.

400

 Describe what a memory leak is and how it can affect a program.

A memory leak occurs when dynamically allocated memory is not freed, leading to reduced performance or system crashes as memory is exhausted.

400

Give an example of reading a single character from a file using fget().

FILE *file = fopen("example.txt", "r");

char c = fgetc(file);

fclose(file);


400

Define a struct that could be used to store information about a student (including student ID and GPA) both without a typedef and with a typedef.

struct student {

    int id;

    float gpa;

};


typedef struct student Student;

Student s = {123, 3.5};





400

Which SDL function flip the video buffers 

int SDL_Flip(SDL_Surface *screen)

500

Write a scanf format string to read a string that includes any lowercase letters, digits, and the underscore character, ensuring it stops reading if it encounters any whitespace.

"%[0-9a-z_]s"

500

 Write a short code to allocate and initialize an array of 10 integers where each element is equal to its index multiplied by 5.

int* array = malloc(10 * sizeof(int));

for (int i = 0; i < 10; i++) {

    array[i] = i * 5;

}


500

 Describe the difference between fwrite() and fprintf()

fwrite() is used for writing binary data to a file, while fprintf() is used to write formatted text data.

500

Explain the difference between a stack and a queue.

A stack is a last-in-first-out (LIFO) data structure, while a queue is a first-in-first-out (FIFO) structure.

500

On a 64-bit system, describe the stack layout during a function call. Include details about the stack frame components such as local variables, function parameters, return address, and the role of the base pointer (RBP) and stack pointer (RSP).

  +---------------------+

  |   Return Address    |

  +---------------------+

  | Old Base Pointer    |

  +---------------------+

  | Function Parameters |

  +---------------------+

  |   Local Variables   |

  +---------------------+

  |   Saved Registers   |

  +---------------------+

  |   Available Space   |

  +---------------------+

  |   Current RSP       |

  +---------------------+


M
e
n
u