Practice 20 Functions & Storage Classes multiple-choice questions designed for CDAC CCAT exam preparation. Click "Show Answer" to reveal the correct option with detailed explanation.
Show Answer & Explanation
Correct Answer: B — int func();
In C, a function declaration specifies the return type and function name.
What will be the output?
void fun()
{
printf("Hello");
}
int main()
{
fun();
return 0;
}Show Answer & Explanation
Correct Answer: A — Hello
The function fun() is called from main(), so it prints Hello.
Show Answer & Explanation
Correct Answer: C — void
void functions are used when no value needs to be returned.
Show Answer & Explanation
Correct Answer: C — Passing copy of variable
In call by value, a copy of the variable is passed to the function.
What will be the output?
void fun(int x)
{
x = x + 5;
}
int main()
{
int a = 10;
fun(a);
printf("%d", a);
return 0;
}Show Answer & Explanation
Correct Answer: A — 10
Since call by value is used, changes inside function do not affect original variable.
Show Answer & Explanation
Correct Answer: B — Pointers
C uses pointers to simulate call by reference.
What will be the output?
void fun(int *x)
{
*x = *x + 5;
}
int main()
{
int a = 10;
fun(&a);
printf("%d", a);
return 0;
}Show Answer & Explanation
Correct Answer: B — 15
Here address of a is passed, so original value gets modified.
Show Answer & Explanation
Correct Answer: A — Function calls itself
A recursive function is one that calls itself.
Show Answer & Explanation
Correct Answer: B — Stops recursion
Without a base condition, recursion becomes infinite.
What will be the output?
int fun(int n)
{
if(n==0) return 0;
return n + fun(n-1);
}
int main()
{
printf("%d", fun(3));
return 0;
}Show Answer & Explanation
Correct Answer: B — 6
This computes sum 3+2+1 using recursion.
Show Answer & Explanation
Correct Answer: C — static
static variables retain their value even after function execution ends.
Show Answer & Explanation
Correct Answer: C — auto
Local variables are auto by default.
Show Answer & Explanation
Correct Answer: C — extern
extern allows sharing global variables across multiple files.
What will be the output?
void fun()
{
static int x = 0;
x++;
printf("%d", x);
}
int main()
{
fun();
fun();
return 0;
}Show Answer & Explanation
Correct Answer: B — 12
static variable retains its value between function calls.
Show Answer & Explanation
Correct Answer: C — register
register improves access speed by suggesting register storage.
Show Answer & Explanation
Correct Answer: C — May not have address
register variables may not have memory address.
Show Answer & Explanation
Correct Answer: C — Function declaration
Prototype informs compiler about function return type and parameters.
Show Answer & Explanation
Correct Answer: C — functions
Recursion is achieved using functions.
Show Answer & Explanation
Correct Answer: C — Undefined behavior
Missing return in non-void function leads to undefined behavior.
Show Answer & Explanation
Correct Answer: C — static
static global variables are restricted to the file scope.