What does the 'const' keyword do when applied to a pointer?
'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?
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?
'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?
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?
5 (binary 101) & 3 (binary 011) = 001 (binary) = 1. Bitwise AND operates on each bit position.
Advertisement
Consider a function declared as 'static int func()'. What is the scope of this function?
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);?
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?
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?
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?
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);
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?
By C standard, sizeof(char) is always 1 byte, regardless of platform.
What does the 'extern' keyword indicate in C?
'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);
%c format specifier prints the character representation of ASCII value 65, which is 'A'.
Which header file is required to use the malloc() function?
malloc() and other dynamic memory allocation functions are declared in <stdlib.h>.
What is the result of: int x = 10; int y = x++ + x++;
Multiple post-increments without sequence points lead to undefined behavior.
In C, which of the following correctly declares a pointer to an integer?
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?
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));
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?
All three are valid ways to work with strings in C, though they differ in memory allocation and mutability.