0% found this document useful (0 votes)
28 views4 pages

C Functions Practice Test

Uploaded by

o230092
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
28 views4 pages

C Functions Practice Test

Uploaded by

o230092
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 4

# ■ Functions in C – Practice Test (25 Questions)

### Part A – Theory (MCQs)

1. Which of the following is mandatory in every C program?


a) main() b) printf() c) scanf() d) clrscr()

2. Default return type of a function in C (if not specified) is:


a) int b) float c) void d) double

3. A function that calls itself is called:


a) Inline function b) Recursive function c) Nested function d) Static function

4. Variables declared inside a function are:


a) Global b) Local c) Static d) External

5. Which keyword is used if a function does not return any value?


a) int b) return c) void d) main

6. Function prototype is written to:


a) Allocate memory
b) Inform compiler about function name, return type & parameters
c) Execute function
d) Define body of function

7. In call by value, changes made inside the function:


a) Affect original variable
b) Do not affect original variable
c) Always produce error
d) Work only for integers

8. Which of the following is NOT a valid return type of a function in C?


a) int b) float c) void d) function

9. When actual parameters are passed by reference:


a) Function gets copy of values
b) Function works with original variables
c) No values are passed
d) Only global variables can be used

10. Which statement is correct about main() in C?


a) Must always return void
b) Must always return int
c) May return int or void depending on compiler
d) Cannot return value

### Part B – Code Output / MCQs

11. Output:
#include
int add(int a, int b) { return a + b; }
int main() { printf("%d", add(2,3)); return 0; }

a) 23 b) 5 c) Error d) Garbage

12. Output:
#include
void greet() { printf("Hi "); }
int main() { greet(); greet(); return 0; }

a) Hi b) Hi Hi c) Error d) Nothing

13. Output:
#include
void fun(int x) { x = x + 5; printf("%d ", x); }
int main() { int a = 10; fun(a); printf("%d", a); return 0; }

a) 15 15 b) 15 10 c) 10 15 d) Error

14. Output:
#include
void disp(int n) { if(n==0) return; printf("%d ", n); disp(n-1); }
int main() { disp(3); return 0; }

a) 1 2 3 b) 3 2 1 c) 3 d) Error

15. Output:
#include
void test() { static int x=0; x++; printf("%d ", x); }
int main() { test(); test(); test(); return 0; }

a) 1 1 1 b) 1 2 3 c) 0 1 2 d) Error

16. Output:
#include
int calc(int n) { if(n==1) return 1; return n + calc(n-1); }
int main() { printf("%d", calc(4)); return 0; }

a) 4 b) 10 c) 1 d) Error

17. Output:
#include
void swap(int a,int b){int t=a;a=b;b=t;}
int main(){int x=5,y=10; swap(x,y); printf("%d %d",x,y); return 0;}

a) 10 5 b) 5 10 c) Error d) Undefined

18. Output:
#include
int test(){ return 10; return 20; }
int main(){ printf("%d", test()); return 0; }

a) 10 b) 20 c) 30 d) Error

19. Output:
#include
int fun(int a){ if(a==0) return 0; else return a+fun(a-1); }
int main(){ printf("%d", fun(5)); return 0; }

a) 5 b) 10 c) 15 d) Error

20. Output:
#include
void show();
int main(){ show(); return 0; }
void show(){ printf("Functions in C"); }

a) Error b) Error c) Functions in C d) Nothing

21. Output:
#include
void printNum(int n){ printf("%d ",n); }
int main(){ printNum(7); printNum(3); return 0; }

a) 7 b) 3 c) 7 3 d) Error

22. Output:
#include
int sum(int a,int b){ return a+b; }
int main(){ int x=2,y=4; printf("%d",sum(x,y)); return 0; }

a) 6 b) 24 c) 2 d) Error

23. Output:
#include
void increment(int n){ n=n+1; printf("%d ", n); }
int main(){ int a=5; increment(a); printf("%d", a); return 0; }

a) 6 6 b) 6 5 c) 5 6 d) 5 5

24. Output:
#include
void countDown(int n){ if(n==0) return; printf("%d ", n); countDown(n-1); }
int main(){ countDown(4); return 0; }

a) 1 2 3 4 b) 4 3 2 1 c) 4 d) Error

25. Output:
#include
int factorial(int n){ if(n==0) return 1; return n*factorial(n-1); }
int main(){ printf("%d", factorial(3)); return 0; }

a) 3 b) 6 c) 0 d) 1

You might also like