Showing 491–499 of 499 questions
What is the output of: printf("%f", 7/2);
A
3.5
B
3.0
C
3
D
undefined
EXPLANATION
7/2 performs integer division resulting in 3. Using %f format specifier prints it as 3.0 (or similar float representation).
What is the scope of a variable declared inside a function in C?
A
Global scope
B
File scope
C
Function scope (local)
D
Extern scope
Correct Answer:
C. Function scope (local)
EXPLANATION
Variables declared inside a function have local scope and are only accessible within that function.
Which of the following correctly represents a character constant in C?
EXPLANATION
Character constants in C use single quotes ('A'). Double quotes ("") are for string literals. A single character in double quotes is a string, not a character constant.
What will happen if we try to modify a const variable in C?
A
Runtime error
B
Compilation error
C
It will modify successfully
D
No error, but warning
Correct Answer:
B. Compilation error
EXPLANATION
Attempting to modify a const variable results in a compilation error as const variables are read-only.
What is the difference between declaration and definition in C?
A
They are the same thing
B
Declaration introduces a name; definition allocates memory
C
Declaration allocates memory; definition introduces a name
D
No difference in C
Correct Answer:
B. Declaration introduces a name; definition allocates memory
EXPLANATION
Declaration tells the compiler about a variable's existence (e.g., 'extern int x;'). Definition allocates actual memory (e.g., 'int x = 5;').
Consider: void func(int *p); Which statement is correct about this function declaration?
A
func takes an integer as parameter
B
func takes a pointer to integer as parameter
C
func returns a pointer
D
func cannot be called
Correct Answer:
B. func takes a pointer to integer as parameter
EXPLANATION
The * in the parameter declaration indicates that func takes a pointer to an integer, not an integer value.
What is the return type of strlen() function?
A
int
B
char
C
size_t
D
float
Correct Answer:
C. size_t
EXPLANATION
strlen() returns size_t, which is an unsigned integer type used for sizes and counts.
Which of the following is the correct way to define a constant in C?
A
#define PI 3.14
B
const float PI = 3.14;
C
Both A and B are correct
D
Neither A nor B is correct
Correct Answer:
C. Both A and B are correct
EXPLANATION
Both #define and const can be used to define constants in C. #define is a preprocessor directive, while const is a type qualifier.
Which of the following is NOT a valid C keyword?
A
extern
B
volatile
C
mutable
D
register
Correct Answer:
C. mutable
EXPLANATION
mutable is a C++ keyword, not a C keyword. extern, volatile, and register are valid C keywords.