Showing 931–940 of 1,000 questions
What will be printed by: printf("%d", sizeof(float));
A
2
B
4
C
8
D
Compiler dependent
EXPLANATION
On most systems, sizeof(float) is 4 bytes. Though technically implementation-defined, 4 bytes is standard.
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))
Correct Answer:
A. #define MAX(a, b) ((a) > (b) ? (a) : (b))
EXPLANATION
The correct syntax uses #define followed by macro name and parameters, with the replacement text in parentheses.
What does the 'static' keyword do when used with a global variable?
A
Makes it constant
B
Limits its scope to the current file
C
Allocates it on the stack
D
Requires initialization
Correct Answer:
B. Limits its scope to the current file
EXPLANATION
Static global variables have internal linkage, restricting visibility to the translation unit where they are defined.
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 *;
Correct Answer:
A. int *ptr;
EXPLANATION
The correct syntax is 'int *ptr;' where * indicates ptr is a pointer to int.
What is the result of: int x = 10; int y = x++ + x++;
A
y = 20
B
y = 21
C
y = 22
D
Undefined behavior
Correct Answer:
D. Undefined behavior
EXPLANATION
Multiple post-increments without sequence points lead to undefined behavior.
Which header file is required to use the malloc() function?
EXPLANATION
malloc() and other dynamic memory allocation functions are declared in <stdlib.h>.
What is the output of: char c = 65; printf("%c", c);
A
65
B
A
C
Invalid output
D
Compilation error
EXPLANATION
%c format specifier prints the character representation of ASCII value 65, which is 'A'.
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).
In C, what is the size of the 'char' data type?
A
1 bit
B
1 byte
C
2 bytes
D
4 bytes
Correct Answer:
B. 1 byte
EXPLANATION
By C standard, sizeof(char) is always 1 byte, regardless of platform.
What will be the output of: int x = 5; printf("%d", x++ + ++x);
A
11
B
12
C
10
D
Undefined behavior
Correct Answer:
D. Undefined behavior
EXPLANATION
This exhibits undefined behavior due to multiple modifications of the same variable 'x' without intervening sequence points.