Showing 921–930 of 1,000 questions
What will be the output of: int x = 10; printf("%d", x++);
A
10
B
11
C
Undefined
D
Error
EXPLANATION
x++ is post-increment. The current value (10) is printed first, then x is incremented to 11. So output is 10.
Which of the following is NOT a valid C data type?
A
int
B
string
C
double
D
char
Correct Answer:
B. string
EXPLANATION
C does not have a built-in 'string' data type. Strings are arrays of characters. int, double, and char are valid primitive data types.
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
Correct Answer:
B. A suggestion to the compiler to inline function calls
EXPLANATION
'inline' is a hint to the compiler suggesting it should inline the function, though the compiler may ignore it.
What will be printed by: int arr[3] = {1, 2, 3}; printf("%d", *(arr + 1));
EXPLANATION
arr + 1 points to the second element, so *(arr + 1) dereferences it to give 2.
What is the scope of a variable declared inside a block with 'static'?
A
Global scope
B
Function scope
C
Block scope with static storage duration
D
File scope
Correct Answer:
C. Block scope with static storage duration
EXPLANATION
A static variable declared in a block has block scope but static storage duration, persisting between function calls.
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
Correct Answer:
D. Both B and C
EXPLANATION
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 the output of: printf("%d", 5 / 2);
EXPLANATION
Integer division truncates the result. 5/2 = 2 (not 2.5) because both operands are integers.
In C, what is the difference between #include 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
Correct Answer:
B. searches standard directories; "" searches current directory first
EXPLANATION
Angle brackets search standard include directories, while quotes search the current directory first, then standard directories.
What is the output of: int x = 5; int y = ++x + x++;
A
y = 12
B
y = 13
C
Undefined behavior
D
Compilation error
Correct Answer:
C. Undefined behavior
EXPLANATION
This involves undefined behavior due to modification of x multiple times without intervening sequence points.
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
Correct Answer:
D. All of the above
EXPLANATION
All three are valid ways to work with strings in C, though they differ in memory allocation and mutability.