C Programming

Functions & Storage Classes — Practice MCQs for CCAT

20 Questions Section B: Programming C Programming

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.

Q1.
What is the correct way to declare a function in C?
Afunc();
Bint func();
Cdeclare func();
Dfunction func();
Show Answer & Explanation

Correct Answer: B — int func();

In C, a function declaration specifies the return type and function name.

Q2.

What will be the output?


void fun()
{
  printf("Hello");
}
int main()
{
  fun();
  return 0;
}
AHello
BNo output
CCompilation error
DRuntime error
Show Answer & Explanation

Correct Answer: A — Hello

The function fun() is called from main(), so it prints Hello.

Q3.
Which type of function does not return any value?
Aint
Bfloat
Cvoid
Dchar
Show Answer & Explanation

Correct Answer: C — void

void functions are used when no value needs to be returned.

Q4.
What is call by value?
APassing address
BPassing reference
CPassing copy of variable
DPassing pointer
Show Answer & Explanation

Correct Answer: C — Passing copy of variable

In call by value, a copy of the variable is passed to the function.

Q5.

What will be the output?


void fun(int x)
{
  x = x + 5;
}
int main()
{
  int a = 10;
  fun(a);
  printf("%d", a);
  return 0;
}
A10
B15
C5
DError
Show Answer & Explanation

Correct Answer: A — 10

Since call by value is used, changes inside function do not affect original variable.

Q6.
What is call by reference implemented using in C?
AVariables
BPointers
CArrays
DStructures
Show Answer & Explanation

Correct Answer: B — Pointers

C uses pointers to simulate call by reference.

Q7.

What will be the output?


void fun(int *x)
{
  *x = *x + 5;
}
int main()
{
  int a = 10;
  fun(&a);
  printf("%d", a);
  return 0;
}
A10
B15
C5
DError
Show Answer & Explanation

Correct Answer: B — 15

Here address of a is passed, so original value gets modified.

Q8.
Which of the following is true about recursion?
AFunction calls itself
BUses loop internally
CExecutes once
DHas no base condition
Show Answer & Explanation

Correct Answer: A — Function calls itself

A recursive function is one that calls itself.

Q9.
Why is base condition important in recursion?
AImproves speed
BStops recursion
CAllocates memory
DCalls main()
Show Answer & Explanation

Correct Answer: B — Stops recursion

Without a base condition, recursion becomes infinite.

Q10.

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;
}
A3
B6
C0
DError
Show Answer & Explanation

Correct Answer: B — 6

This computes sum 3+2+1 using recursion.

Q11.
Which storage class gives variable local scope but retains value between calls?
Aauto
Bextern
Cstatic
Dregister
Show Answer & Explanation

Correct Answer: C — static

static variables retain their value even after function execution ends.

Q12.
What is the default storage class of local variables?
Astatic
Bextern
Cauto
Dregister
Show Answer & Explanation

Correct Answer: C — auto

Local variables are auto by default.

Q13.
Which storage class is used to access global variable from another file?
Astatic
Bauto
Cextern
Dregister
Show Answer & Explanation

Correct Answer: C — extern

extern allows sharing global variables across multiple files.

Q14.

What will be the output?


void fun()
{
  static int x = 0;
  x++;
  printf("%d", x);
}
int main()
{
  fun();
  fun();
  return 0;
}
A11
B12
C01
DError
Show Answer & Explanation

Correct Answer: B — 12

static variable retains its value between function calls.

Q15.
Which storage class suggests compiler to store variable in CPU register?
Aauto
Bstatic
Cregister
Dextern
Show Answer & Explanation

Correct Answer: C — register

register improves access speed by suggesting register storage.

Q16.
Which of the following is true about register variables?
AAddress can be accessed
BStored in RAM
CMay not have address
DGlobal scope
Show Answer & Explanation

Correct Answer: C — May not have address

register variables may not have memory address.

Q17.
What is function prototype?
AFunction body
BFunction call
CFunction declaration
DReturn statement
Show Answer & Explanation

Correct Answer: C — Function declaration

Prototype informs compiler about function return type and parameters.

Q18.
Which of the following supports recursion best?
Afor loop
Bgoto
Cfunctions
Dmacros
Show Answer & Explanation

Correct Answer: C — functions

Recursion is achieved using functions.

Q19.
What happens if return statement is missing in non-void function?
AReturns 0
BCompilation error
CUndefined behavior
DReturns garbage
Show Answer & Explanation

Correct Answer: C — Undefined behavior

Missing return in non-void function leads to undefined behavior.

Q20.
Which storage class limits variable scope to the file only?
Aextern
Bauto
Cstatic
Dregister
Show Answer & Explanation

Correct Answer: C — static

static global variables are restricted to the file scope.