What does the 'const' keyword do when applied to a pointer?
A Makes the pointer value constant only B Makes the pointed data constant only C Can make either or both constant depending on placement D Has no effect in C
'const int *ptr' makes the data constant, 'int * const ptr' makes the pointer constant, and 'const int * const ptr' makes both constant.
Which of the following is a correct way to read a string from user input avoiding buffer overflow?
A scanf("%s", str); B scanf("%10s", str); C gets(str); D scanf("%[^ ]s", str);
Using scanf("%10s", str) limits input to 10 characters, preventing buffer overflow. The gets() function is deprecated and unsafe.
What is the difference between 'break' and 'continue' statements in C?
A 'break' stops execution while 'continue' skips iteration B Both have the same function C 'continue' stops execution while 'break' skips iteration D Neither has practical use in loops
'break' terminates the loop entirely, while 'continue' skips the current iteration and moves to the next one.
In C, what is the correct way to pass a variable by reference using pointers?
A void func(int var) { var = 10; } B void func(int &var) { var = 10; } C void func(int *var) { *var = 10; } D void func(int *var) { var = 10; }
C uses pointers for pass-by-reference. The dereference operator '*var' accesses the actual variable. C++ supports references (&var), but C does not.
What will be the result of the bitwise operation: 5 & 3 in C?
A 1 B 7 C 6 D 4
5 (binary 101) & 3 (binary 011) = 001 (binary) = 1. Bitwise AND operates on each bit position.
Consider a function declared as 'static int func()'. What is the scope of this function?
A Global scope across all files B Limited to the current file only C Only within the function where it's declared D Limited to the current block
When 'static' is applied to a function at file scope, it restricts the function's visibility to that translation unit (file) only.
What is the output of: printf("%d", (int)3.7);?
A 3.7 B 3 C 4 D Error
Type casting (int)3.7 truncates the decimal part, converting 3.7 to 3. The fractional part is discarded.
Which of the following best describes the 'register' storage class in modern C compilers?
A Guarantees storage in CPU register B A hint to the compiler to optimize variable storage; compiler may ignore it C Forces the variable to be global D Automatically allocates memory on the stack
The 'register' keyword is a hint for compiler optimization. Modern compilers often ignore it as they have sophisticated optimization strategies.
What is the size of the 'int' data type in a 32-bit system according to C standard?
A 2 bytes B 4 bytes C 8 bytes D Platform dependent
The size of 'int' is implementation-defined and depends on the compiler and platform, though it is typically 4 bytes on 32-bit systems.
Which of the following is NOT a valid C identifier?
A _variable123 B 123variable C variable_123 D __var__
Identifiers cannot start with a digit. They must start with a letter (a-z, A-Z) or underscore.
What will be the output of: int x = 5; printf("%d", x++ + ++x);
A 11 B 12 C 10 D Undefined behavior
This exhibits undefined behavior due to multiple modifications of the same variable 'x' without intervening sequence points.
In C, what is the size of the 'char' data type?
A 1 bit B 1 byte C 2 bytes D 4 bytes
By C standard, sizeof(char) is always 1 byte, regardless of platform.
What does the 'extern' keyword indicate in C?
A A variable exists in another source file B A variable is local to a function C A variable cannot be modified D A variable is allocated on the stack
'extern' declares a variable or function that is defined in another translation unit (source file).
What is the output of: char c = 65; printf("%c", c);
A 65 B A C Invalid output D Compilation error
%c format specifier prints the character representation of ASCII value 65, which is 'A'.
Which header file is required to use the malloc() function?
A <stdio.h> B <stdlib.h> C <string.h> D <math.h>
malloc() and other dynamic memory allocation functions are declared in <stdlib.h>.
What is the result of: int x = 10; int y = x++ + x++;
A y = 20 B y = 21 C y = 22 D Undefined behavior
Multiple post-increments without sequence points lead to undefined behavior.
In C, which of the following correctly declares a pointer to an integer?
A int *ptr; B *int ptr; C int& ptr; D pointer int *;
The correct syntax is 'int *ptr;' where * indicates ptr is a pointer to int.
What is the correct syntax to define a macro with arguments in C?
A #define MAX(a, b) ((a) > (b) ? (a) : (b)) B #macro MAX(a, b) ((a) > (b) ? (a) : (b)) C #define MAX a, b ((a) > (b) ? (a) : (b)) D define MAX(a, b) ((a) > (b) ? (a) : (b))
The correct syntax uses #define followed by macro name and parameters, with the replacement text in parentheses.
What will be printed by: printf("%d", sizeof(float));
A 2 B 4 C 8 D Compiler dependent
On most systems, sizeof(float) is 4 bytes. Though technically implementation-defined, 4 bytes is standard.
Which of the following is a correct way to initialize a character array with a string?
A char str[] = "Hello"; B char str[5] = "Hello"; C char *str = "Hello"; D All of the above
All three are valid ways to work with strings in C, though they differ in memory allocation and mutability.