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.
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 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.
Advertisement
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.
In C, what is the difference between #include <stdio.h> and #include "stdio.h"?
A They are identical B <> searches standard directories; "" searches current directory first C "" is only for user-defined headers D <> is only for system headers
Angle brackets search standard include directories, while quotes search the current directory first, then standard directories.
Which of the following statements about NULL is correct?
A NULL is a keyword in C B NULL is typically defined as (void *)0 C NULL and 0 are interchangeable for pointers D Both B and C
NULL is a macro (not a keyword) typically defined as (void *)0, and can be used interchangeably with 0 for pointer assignments.
What will be printed by: int arr[3] = {1, 2, 3}; printf("%d", *(arr + 1));
A 1 B 2 C 3 D Undefined
arr + 1 points to the second element, so *(arr + 1) dereferences it to give 2.
In C99 and later standards, what is the purpose of 'inline' keyword?
A To declare variables inline B A suggestion to the compiler to inline function calls C To restrict variable scope D To allocate memory inline
'inline' is a hint to the compiler suggesting it should inline the function, though the compiler may ignore it.
What is the purpose of the getchar() function in C?
A Get a string from input B Get a single character from input C Get a number from input D Get a pointer from input
getchar() reads a single character from standard input and returns it. For strings, fgets() or scanf() is used.
What will be the output of: int a = 5; int b = a < 10 ? 20 : 30; printf("%d", b);
A 5 B 10 C 20 D 30
This is the ternary operator. Since 5 < 10 is true, b = 20. If false, b would be 30.
Which of the following is correct about static variables in C?
A They are destroyed after function returns B They retain their value between function calls C They cannot be used in functions D They are global by default
Static variables retain their value between function calls and are initialized only once. They persist for the lifetime of the program.
What is the output of: printf("%d %d", 10 % 3, 3 10 );
A 3 3 B 1 3 C 3 1 D 10 10
10 % 3 = 1 (remainder), 3 10 = 3 (integer division). Output is '1 3'.
What does the 'volatile' keyword in C indicate?
A Variable value can change unexpectedly B Variable is constant C Variable is local D Variable must be initialized
volatile tells the compiler that a variable's value can change unexpectedly (e.g., in hardware registers or interrupt handlers), so it should not optimize away repeated reads.
Which of the following about register variables is TRUE?
A They must be initialized B They are faster to access than normal variables C They cannot be pointers D They are stored in RAM
register keyword suggests the compiler to store the variable in CPU register for faster access. Modern compilers often ignore this hint. You cannot take address of register variables.
Consider the following code:
int x = 5;
int *ptr = &x;
int pptr = &ptr;
printf("%d", pptr);
What is the output?
A 5 B Address of x C Address of ptr D Compilation Error
pptr is a pointer to pointer. **pptr dereferences twice: first to get ptr, then to get x's value which is 5.
What will be printed by the following code?
#include<stdio.h>
int main() {
int arr[5] = {1, 2, 3, 4, 5};
int *p = arr;
printf("%d %d", *(p+2), arr[2]);
return 0;
}
A 3 3 B 2 4 C 4 3 D 3 4
*(p+2) accesses the element at index 2 (value 3), and arr[2] also accesses index 2 (value 3). Both print 3.
What is the output of this code?
#include<stdio.h>
int main() {
int a = 5, b = 10;
a = a ^ b;
b = a ^ b;
a = a ^ b;
printf("%d %d", a, b);
return 0;
}
A 5 10 B 10 5 C 0 0 D 10 10
This is a classic XOR swap algorithm. After three XOR operations, a and b exchange their values. Result: a=10, b=5.