Showing 471–480 of 499 questions
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
Correct Answer:
A. A variable exists in another source file
EXPLANATION
'extern' declares a variable or function that is defined in another translation unit (source file).
What will be the result of the bitwise operation: 5 & 3 in C?
EXPLANATION
5 (binary 101) & 3 (binary 011) = 001 (binary) = 1. Bitwise AND operates on each bit position.
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; }
Correct Answer:
C. void func(int *var) { *var = 10; }
EXPLANATION
C uses pointers for pass-by-reference. The dereference operator '*var' accesses the actual variable. C++ supports references (&var), but C does not.
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
Correct Answer:
A. 'break' stops execution while 'continue' skips iteration
EXPLANATION
'break' terminates the loop entirely, while 'continue' skips the current iteration and moves to the next one.
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);
Correct Answer:
B. scanf("%10s", str);
EXPLANATION
Using scanf("%10s", str) limits input to 10 characters, preventing buffer overflow. The gets() function is deprecated and unsafe.
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
Correct Answer:
C. Can make either or both constant depending on placement
EXPLANATION
'const int *ptr' makes the data constant, 'int * const ptr' makes the pointer constant, and 'const int * const ptr' makes both constant.
In C, which operator has the highest precedence?
A
Multiplicative operators (*, /, %)
B
Postfix operators (++, --)
C
Additive operators (+, -)
D
Assignment operators (=)
Correct Answer:
B. Postfix operators (++, --)
EXPLANATION
Postfix operators ([], ., ->, ++, --) have the highest precedence in C, followed by unary and then binary operators.
What is the primary purpose of the 'volatile' keyword in C?
A
To prevent variable modification
B
To inform the compiler that a variable's value can change unexpectedly
C
To allocate memory dynamically
D
To declare function pointers
Correct Answer:
B. To inform the compiler that a variable's value can change unexpectedly
EXPLANATION
The 'volatile' keyword tells the compiler not to optimize accesses to a variable, as its value can change from external sources (hardware, signals, etc.).
Which of the following correctly represents a string literal in C?
A
char str = 'Hello';
B
char str[] = "Hello";
C
string str = "Hello";
D
char *str = 'Hello';
Correct Answer:
B. char str[] = "Hello";
EXPLANATION
Strings in C are represented using double quotes and stored in character arrays. Single quotes are for single characters.
What will be the output of the expression: 5/2 in C (considering integer division)?
EXPLANATION
In C, when both operands are integers, division performs integer division, discarding the fractional part. 5/2 = 2.