Who developed the C programming language?
- A. Bjarne Stroustrup
- B. James Gosling
- C. Dennis Ritchie (correct)
- D. Guido van Rossum
Which function is the entry point of a C program?
- A. main() (correct)
- B. start()
- C. begin()
- D. run()
Which header file is needed for printf()?
- A. stdlib.h
- B. stdio.h (correct)
- C. string.h
- D. math.h
Which format specifier prints an integer?
- A. %f
- B. %c
- C. %s
- D. %d (correct)
Every statement in C ends with:
- A. :
- B. .
- C. ; (correct)
- D. ,
What is the typical size of an int on most modern systems?
- A. 2 bytes
- B. 4 bytes (correct)
- C. 8 bytes
- D. 1 byte
Which of these is NOT a loop in C?
- A. for
- B. while
- C. foreach (correct)
- D. do-while
What does the & operator give in C?
- A. Address of a variable (correct)
- B. Value of a variable
- C. Logical OR
- D. Size of a variable
Which is the correct way to declare an integer pointer?
- A. int p*;
- B. pointer int p;
- C. int &p;
- D. int *p; (correct)
What is the output of printf("%d", 5/2);?
- A. 2.5
- B. 2 (correct)
- C. 3
- D. 2.0
What does malloc() return?
- A. int
- B. char
- C. void pointer (correct)
- D. float
At which index does a C array start?
- A. 0 (correct)
- B. 1
- C. -1
- D. Depends on the compiler
Which function copies one string into another?
- A. strcmp()
- B. strlen()
- C. strcat()
- D. strcpy() (correct)
How many bytes does char s[] = "hi"; occupy?
- A. 2
- B. 4
- C. 3 (correct)
- D. 1
What does free() do?
- A. Allocates memory
- B. Releases dynamically allocated memory (correct)
- C. Closes a file
- D. Clears the screen
What is a dangling pointer?
- A. A pointer that is always NULL
- B. A pointer to an integer array
- C. A constant pointer
- D. A pointer to memory that has been freed or is invalid (correct)
What does the static keyword do for a local variable?
- A. Makes it global
- B. Retains its value between function calls (correct)
- C. Makes it constant
- D. Stores it in a register
What usually causes a segmentation fault?
- A. Missing semicolon
- B. Using too many variables
- C. Accessing invalid memory (correct)
- D. Using printf()
Memory allocated with malloc() comes from the:
- A. Heap (correct)
- B. Stack
- C. Register
- D. Code segment
What is sizeof(char) in C?
- A. 2
- B. 4
- C. 1 (correct)
- D. Implementation defined
Which format specifier prints a float with printf?
- A. %d
- B. %c
- C. %f (correct)
- D. %s
Which format specifier prints a single character?
- A. %ch
- B. %d
- C. %c (correct)
- D. %s
Which format specifier prints a string?
- A. %d
- B. %s (correct)
- C. %str
- D. %c
Which function reads formatted input from the keyboard?
- A. input()
- B. printf()
- C. scanf() (correct)
- D. gets_int()
Why do you write &x in scanf("%d", &x);?
- A. It is optional decoration
- B. To make x a pointer type
- C. To print x
- D. scanf needs the address of x to store the value (correct)
Which keyword is used to make a decision in C?
- A. case only
- B. when
- C. if (correct)
- D. decide
Which loop checks its condition after running the body?
- A. while
- B. do-while (correct)
- C. for
- D. foreach
Which keyword exits a switch case or loop?
- A. break (correct)
- B. return only
- C. stop
- D. exit
What is the return type of main in a standard C program?
- A. int (correct)
- B. void only
- C. char
- D. float
What does return 0; at the end of main usually mean?
- A. The program failed
- B. The program restarts
- C. Nothing is returned
- D. The program finished successfully (correct)
How do you write a multi-line comment in C?
- A. <!-- comment -->
- B. // comment //
- C. # comment #
- D. /* comment */ (correct)
Which data type stores decimal numbers with double precision?
- A. long
- B. int
- C. float only
- D. double (correct)
Which operator gets the value stored at a pointer's address?
- A. * (correct)
- B. &
- C. ->
- D. .
How do you declare an array of 10 integers?
- A. int a[10]; (correct)
- B. int[10] a;
- C. int a(10);
- D. array int a = 10;
What character marks the end of a C string?
- A. '\n'
- B. ' '
- C. '\0' (the null character) (correct)
- D. '.'
Which header file is needed for strlen()?
- A. <stdlib.h>
- B. <string.h> (correct)
- C. <stdio.h>
- D. <math.h>
Which header file is needed for malloc()?
- A. <stdlib.h> (correct)
- B. <memory.h> only
- C. <string.h>
- D. <stdio.h>
What does the ++ operator do?
- A. Increases a variable by 1 (correct)
- B. Doubles a variable
- C. Prints a variable
- D. Adds two variables
Which statement selects one of many branches based on an integer value?
- A. goto
- B. select
- C. if-else only
- D. switch (correct)
What is the value of 7 % 3 in C?
- A. 1 (correct)
- B. 2.33
- C. 0
- D. 2
What is the difference between i++ and ++i?
- A. i++ uses the old value then increments; ++i increments first (correct)
- B. i++ increments by 2
- C. ++i is invalid in C
- D. They are always different in value after the statement
What does sizeof(int) typically return on a 64-bit Linux system?
- A. 8
- B. 16
- C. 4 (correct)
- D. 2
What does the -> operator do?
- A. Assigns a pointer
- B. Accesses a struct member through a pointer (correct)
- C. Compares pointers
- D. Points to the next line
What is a struct in C?
- A. A function
- B. A pointer type
- C. A user-defined type grouping variables of different types (correct)
- D. A loop
What is the difference between a struct and a union?
- A. All union members share the same memory; struct members each have their own (correct)
- B. A union cannot hold integers
- C. They are identical
- D. A struct shares memory
What does the typedef keyword do?
- A. Converts types
- B. Checks a type at runtime
- C. Creates a new name for an existing type (correct)
- D. Defines a new variable
What does an enum define?
- A. A pointer type
- B. A dynamic array
- C. A set of named integer constants (correct)
- D. A list of strings
What does #define PI 3.14 do?
- A. Includes a file
- B. Declares a variable PI
- C. Defines a function
- D. Defines a macro replaced by the preprocessor before compiling (correct)
What does #include do?
- A. Defines a macro
- B. Links a library at runtime
- C. Inserts the contents of another file before compilation (correct)
- D. Starts the main function
What does calloc() do differently from malloc()?
- A. It is faster always
- B. It allocates on the stack
- C. It frees memory
- D. It sets the allocated memory to zero (correct)
What does realloc() do?
- A. Frees memory
- B. Allocates a string
- C. Changes the size of previously allocated memory (correct)
- D. Copies a file
What is a memory leak?
- A. Reading uninitialized memory
- B. Allocated memory that is never freed (correct)
- C. Memory that is too slow
- D. A buffer that is too small
What does strcmp(a, b) return when the strings are equal?
- A. true
- B. 1
- C. -1
- D. 0 (correct)
Which function joins two strings?
- A. strcpy()
- B. strcat() (correct)
- C. concat()
- D. strjoin()
What is a function prototype?
- A. A function with no body ever
- B. A macro
- C. A declaration of a function's name, return type and parameters before its use (correct)
- D. The first function in a file
How are arrays passed to functions in C?
- A. By value only
- B. As a pointer to their first element (correct)
- C. As a full copy
- D. They cannot be passed
What does a pointer to a pointer (int **p) store?
- A. A function
- B. Two integers
- C. An array of strings only
- D. The address of another pointer (correct)
What is the result of 5 / 2.0 in C?
- A. 2.0 as an int
- B. 2
- C. 2.5 (correct)
- D. 3
What does the const keyword do in const int x = 5;?
- A. Prevents x from being modified (correct)
- B. Makes x global
- C. Makes x static
- D. Makes x a macro
What does the extern keyword mean?
- A. The variable is on the heap
- B. The variable is external memory
- C. The variable is defined in another file (correct)
- D. The variable is constant
What is recursion in C?
- A. A macro expanding itself
- B. A function calling itself (correct)
- C. A loop with goto
- D. A struct inside a struct
Which function opens a file in C?
- A. fileopen()
- B. open_file()
- C. fopen() (correct)
- D. readfile()
Which function writes formatted output to a file?
- A. fwrite_text()
- B. fprintf() (correct)
- C. printf()
- D. fputs_format()
Which mode string opens a file for reading in C?
- A. "w"
- B. "read"
- C. "r" (correct)
- D. "a"
What does fclose() do?
- A. Deletes a file
- B. Reads a file
- C. Opens a file
- D. Closes a file and flushes its buffer (correct)
What is a function pointer?
- A. A variable that stores the address of a function (correct)
- B. A pointer to the main function only
- C. A macro
- D. A pointer returned by a function
What is pointer arithmetic for p + 1 when p is an int*?
- A. It is not allowed
- B. It advances by sizeof(int) bytes (correct)
- C. It advances by 1 byte
- D. It adds 1 to the value
What does the volatile keyword tell the compiler?
- A. The value may change unexpectedly, so do not optimize away reads (correct)
- B. The variable is thread-safe
- C. The value is constant
- D. The variable is on the stack
What is a buffer overflow?
- A. Too many open files
- B. Using too many functions
- C. Writing past the end of an array's allocated memory (correct)
- D. A full disk
Why is gets() dangerous and removed from modern C?
- A. It cannot limit input length and causes buffer overflows (correct)
- B. It closes stdin
- C. It only reads numbers
- D. It is too slow
What is the difference between an array name and a pointer?
- A. A pointer cannot be indexed
- B. An array name can be reassigned
- C. An array name is not a modifiable variable and sizeof gives the full array size (correct)
- D. They are exactly the same
What does the restrict keyword promise?
- A. The pointer is read-only
- B. The pointer is aligned
- C. The pointer cannot be null
- D. The pointer is the only way to access that memory in its scope (correct)
What are bit fields in a struct?
- A. Boolean pointers
- B. Bitwise operators
- C. Members with a specified number of bits (correct)
- D. Arrays of bits
What is the output of printf("%d", 1 << 3);?
- A. 4
- B. 13
- C. 8 (correct)
- D. 3
What does the expression x & 1 check?
- A. Whether x is a power of two
- B. Whether x is odd (correct)
- C. Whether x is negative
- D. Whether x is zero
What does the static keyword do on a global function?
- A. Makes it run once
- B. Makes it inline
- C. Limits its visibility to the current file (correct)
- D. Keeps its value between calls
What happens when you return a pointer to a local variable?
- A. The pointer becomes dangling after the function returns (correct)
- B. The variable is copied to the heap
- C. It is safe
- D. A compile error always occurs
What is the purpose of the preprocessor guard #ifndef HEADER_H / #define HEADER_H?
- A. To define a function
- B. To speed up compilation always
- C. To prevent a header from being included twice (correct)
- D. To check for errors
What is the value of sizeof(arr) / sizeof(arr[0]) for int arr[8];?
- A. 8 (correct)
- B. 1
- C. 4
- D. 32
What does void* represent?
- A. A null pointer
- B. A function pointer
- C. A generic pointer to data of any type (correct)
- D. A pointer to nothing that cannot be used