Showing 81–90 of 100 questions
in Basics & Syntax
What is the purpose of the void keyword in C?
A
To declare empty variables
B
To indicate absence of type or empty parameter list
C
To declare null pointers
D
To terminate a program
Correct Answer:
B. To indicate absence of type or empty parameter list
EXPLANATION
void indicates absence of a return type (void function) or an empty parameter list func(void). It can also represent a generic pointer (void *).
Which storage class has a default value of 0 if not explicitly initialized?
A
auto
B
register
C
static
D
extern
Correct Answer:
C. static
EXPLANATION
Static variables are initialized to 0 by default. auto and register variables have garbage values if not initialized. extern variables are declared elsewhere.
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).
Consider the expression: int arr[5]; What does arr represent without the index?
A
The first element of array
B
Base address of the array
C
Error - incomplete expression
D
The entire array as a single value
Correct Answer:
B. Base address of the array
EXPLANATION
In C, the array name arr (without index) decays to a pointer to its first element, representing the base address.
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.