UNIT-III
1. The keyword used to transfer control from a function back to the calling function is
A. switch
B. goto
C. go back
D. return
2. How many times the program will print "Dr.K.K" ?
#include<stdio.h>
jint main()
{
printf("Dr.K.K");
main();
return 0;
}
A. Infinite times
B. 32767 times
C. 65535 times
D. Till stack overflows
3. The default parameter passing mechanism is
A. Call by value
B. call by reference
C. call by value result
D. None
4. Pick the correct statements.
I. The body of a function should have only one return statement.
II. The body of a function may have many return statements.
III. A function can return only one value to the calling environment.
IV. If return statement is omitted, then the function does its job but returns no value to the calling
environment.
A. I and II
B. I and III
C. II and III
D. II and IV
5. In C, what is the meaning of following function prototype with empty parameter list
void fun()
{
/* .... */
}
A. Function can only be called without any parameter
B. Function can be called with any number of parameters of any types
C. Function can be called with any number of integer parameters.
D. Function can be called with one integer parameter.
6. What is the output of this C code?
void main()
{
m();
}
void m()
{
printf("hi");
m();
}
A. Compile time error
B. hi
C. Infinite hi
D. Nothing
7. What is the output of this C code?
void main()
{
m();
void m()
{
printf("hi");
}
}
A. hi
B. Compile time error
C. Nothing
D. Varies
8. What will be the output of the C program?
#include<stdio.h>
int main()
{
main();
return 0;
}
A. Runtime error
B. Compilation error
C. 0
D. none of the above
9. What will be the output of the C program?
#include<stdio.h>
int function();
main()
{
int i;
i = function();
printf("%d", i);
return 0;
}
function()
{
int a;
a = 250;
return 0;
}
A. Runtime error
B. 0
C. 250
D. No output
10. What will be the output of the C program?
#include<stdio.h>
int function(int, int);
int main()
{
int a = 25, b = 24 + 1, c;
printf("%d", function(a, b));
return 0;
}
int function(int x, int y)
{
return (x - (x == y));
}
A. Compilation error
B. 25
C. 1
D. 24✔
11. What will be the output of the C program?
#include<stdio.h>
int main()
{
char arr[] = "function\0";
int num = strlen(a);
printf("Length of function is %d", num);
return 0;
}
A. 9
B. 7
C. 10
D. 8
12. What will be the output of the C program?
#include<stdio.h>
int num = 5;
int main()
{
fun();
fun();
return 0;
}
int fun()
{
static int num = 2;
printf("%d ",num);
num++;
return 0;
}
A. 2 3
B. 2 2
C. 5 5
D. 5 6
13. What will be the output of the C program?
#include<stdio.h>
void fun(int);
int main()
{
int a = 3;
fun(a);
return 0;
}
void fun(int n)
{
if (n > 0)
{
fun(--n);
printf("%d ", n);
}
}
A. 1 2 3
B. No Output
C. 0 1 2
D. 0
14. What will be the output of the C program?
#include<stdio.h>
int main()
{
int i;
i = main();
printf("%d", i);
int main()
{
int a;
a = 5 * 5;
return a;
}
return 0;
}
A. Compilation error
B. Runtime error
C. address
D. 25
15. What will be the output of the C program?
#include<stdio.h>
int swap(int *a, int *b)
{
*a = *a + *b;
*b = *a - *b;
*a = *a - *b;
}
int main()
{
int x = 5, y = 10;
swap(&x, &y);
printf("%d %d\n", x, y);
return 0;
}
A. Runtime error
B. 5 10✘
C. 10 5
D. Compilation error
16. What will be the output of the program?
#include<stdio.h>
int sumdig(int);
int main()
{
int a, b;
a = sumdig(123);
b = sumdig(123);
printf("%d, %d\n", a, b);
return 0;
}
int sumdig(int n)
{
int s, d;
if(n!=0)
{
d = n%10;
n = n/10;
s = d+sumdig(n);
}
else
return 0;
return s;
}
A. 4, 4
B. 3, 3
C. 6, 6
D. 12, 12
17. What will be the output of the program?
#include<stdio.h>
int main()
{
int fun(int);
int i = fun(10);
printf("%d\n", --i);
return 0;
}
int fun(int i)
{
return (i++);
}
A. 9
B. 10
C. 11
D. 8
18. What will be the output of the program?
#include<stdio.h>
int check (int, int);
int main()
{
int c;
c = check(10, 20);
printf("c=%d\n", c);
return 0;
}
int check(int i, int j)
{
int *p, *q;
p=&i;
q=&j;
i>=45 ? return(*p): return(*q);
}
A. Print 10
B. Print 20
C. Print 1
D. Compile error
19. What will be the output of the program?
#include<stdio.h>
int main()
{
int i=1;
if(!i)
printf("Dr.K.Kartheeban,");
else
{
i=0;
printf("C-Program");
main();
}
return 0;
}
A. prints " Dr.K.Kartheeban, C-Program" infinitely
B. prints "C-Program" infinetly
C. prints "C-Program, Dr.K.Kartheeban " infinitely
D. Error: main() should not inside else statement
20. What will be the output of the program?
#include<stdio.h>
int addmult(int ii, int jj)
{
int kk, ll;
kk = ii + jj;
ll = ii * jj;
return (kk, ll);
}
int main()
{
int i=3, j=4, k, l;
k = addmult(i, j);
l = addmult(i, j);
printf("%d %d\n", k, l);
return 0;
}
A. 12 12
B. No error, No output
C. Error: Compile error
D. None of above
21. What will be the output of the program?
#include<stdio.h>
int i;
int fun1(int);
int fun2(int);
int main()
{
extern int j;
int i=3;
fun1(i);
printf("%d,", i);
fun2(i);
printf("%d", i);
return 0;
}
int fun1(int j)
{
printf("%d,", ++j);
return 0;
}
int fun2(int i)
{
printf("%d,", ++i);
return 0;
}
int j=1;
A. 3, 4, 4, 3
B. 4, 3, 4, 3
C. 3, 3, 4, 4
D. 3, 4, 3, 4
22. What will be the output of the program?
#include<stdio.h>
int func1(int);
int main()
{
int k=35;
k = func1(k=func1(k=func1(k)));
printf("k=%d\n", k);
return 0;
}
int func1(int k)
{
k++;
return k;
}
A. k=35
B. k=36
C. k=37
D. k=38
23. What will be the output of the program?
#include<stdio.h>
int check(int);
int main()
{
int i=45, c;
c = check(i);
printf("%d\n", c);
return 0;
}
int check(int ch)
{
if(ch >= 45)
return 100;
else
return 10;
}
A. 100
B. 10
C. 1
D. 0
24. What will be the output of the program?
#include<stdio.h>
int fun(int(*)());
int main()
{
fun(main);
printf("Hi\n");
return 0;
}
int fun(int (*p)())
{
printf("Hello ");
return 0;
}
A. Infinite loop
B. Hi
C. Hello Hi
D. Error
25. What will be the output of the program?
#include<stdio.h>
int fun(int);
int main()
{
float k=3;
fun(k=fun(fun(k)));
printf("%f\n", k);
return 0;
}
int fun(int i)
{
i++;
return i;
}
A. 5.000000
B. 3.000000
C. Garbage value
D. 4.000000
26. Use of functions
A. Helps to avoid repeating a set of statements many times.
B. Enhances the logical clarity of the program.
C. Helps to avoid repeated programming across programs.
D. Makes the debugging task easier.
E. All of the above
27. Any C program
A. Must contain at least one function.
B. Need not contain any function.
C. Needs input data.
D. None of the above
28. What is function?
A. Function is a block of statements that perform some specific task.
B. Function is the fundamental modular unit. A function is usually designed to perform a specific
task.
C. Function is a block of code that performs a specific task. It has a name and it is reusable.
D. All of the above
29. What is the result of compiling and running this code?
main()
{
char string[] = "Hello World";
display(string);
}
void display(char *string)
{
printf("%s", string);
}
A. will print Hello World
B. Compilation Error
C. will print garbage value
D. None of these.
30. Which of the following is a complete function?
A. int funct();
B. int funct(int x) { return x=x+1; }
C. void funct(int) { printf(“Hello"); }
D. void funct(x) { printf(“Hello"); }
31. What will be printed when this program is executed?
int f(int x)
{
if(x <= 4)
return x;
return f(--x);
}
void main()
{
printf("%d ", f(7));
}
A. 4 5 6 7
B. 1 2 3 4
C. 4
D. Syntax error
32. The recursive functions are executed in a ...........
A. Parallel order
B. First In First Out order
C. Last In First Out order
D. Iterative order
33. The function scanf() returns .........
A. The actual values read for each argument.
B. 1
C. 0
D. The number of successful read input values.
34. Which of the following function calculates the square of 'x' in C?
A. sqr(x)
B. pow(2, x)
C. pow(x, 2)
D. power(2, x)
35. When a function is recursively called all the automatic variables are stored in a ..........
A. Stack
B. Queue
C. Array
D. Linked list
36. What will be printed when the sample code above is executed?
char* myfunc(char *ptr)
{
ptr+=3;
return(ptr);
}
void main()
{
char *x, *y;
x = "EXAMVEDA";
y = myfunc(x);
printf("y=%s", y);
}
A. y=EXAMVEDA
B. y=MVEDA
C. y=VEDA
D. y=ED
37. What is the output of this program?
#include<stdio.h>
void fun(int a, ...)
{
printf("%d ", a);
}
int main()
{
fun(1,2,3,4);
fun(5,6,7,8,9);
return 0;
}
A. 1 5
B. 2 5
C. 5 1
D. Compilation Error
38. What is the output of this program?
#include<stdio.h>
int demo()
{
static int i = 0;
printf("%d ",i++);
}
int main()
{
for(int j = 0 ; j < 5 ; j++ )
{
demo();
}
}
A. 0 0 0 0 0
B. 1 1 1 1 1
C. 1 2 3 4 5
D. 0 1 2 3 4
39. What is the output of this program?
#include<stdio.h>
int test()
{
static int n = 10;
return n--;
}
int main()
{
for(test(); test(); test())
printf("%d ", test());
return 0;
}
A. 7 4 1
B. 8 5 2
C. Infinite loop
D. Compilation Error
40. What is the output of this program?
#include<stdio.h>
void test(int *a, int *b)
{
a = b;
*a = 15;
}
int x = 10, y = 20;
int main()
{
test(&x, &y);
printf("%d %d", x, y);
return 0;
}
A. 15 15
B. 10 15
C. 10 20
D. 15 20
41. What is the output of this program?
#include<stdio.h>
void test(int * , int *);
void main()
{
int a = 5 , b = 6;
test(&a,&b);
printf("%d %d",a,b);
}
void test(int *p, int *q)
{
*p = *p * *q;
*q = *p + *q;
*p = *p - *q;
}
A. -6 36
B. 6 36
C. 36 6
D. -6 -36
42. What will be the output of the following C code?
#include<stdio.h>
main()
{
int n;
n=f1(4);
printf("%d",n);
}
f1(int x)
{
int b;
if(x==1)
return 1;
else
b=x*f1(x-1);
return b;
}
a) 24
b) 4
c) 12
d) 10
43. The data structure used to implement recursive function calls _____________
a) Array
b) Linked list
c) Binary tree
d) Stack
44. What will be the output of the following C code?
#include<stdio.h>
main()
{
int n,i;
n=f(6);
printf("%d",n);
}
f(int x)
{
if(x==2)
return 2;
else
{
printf("+");
f(x-1);
}
}
a) ++++2
b) +++++2
c) +++++
d) 2
45. How many times is ‘a’ printed when the following C code is executed?
#include<stdio.h>
main()
{
int a;
a=f1(10);
printf("%d",a);
}
f1(int b)
{
if(b==0)
return 0;
else
{
printf("a");
f1(b--);
}
}
a) 9 times
b) 10 times
c) 0 times
d) Infinite number of times
46. What will be the output of the following C code if the input given to the code shown below is
“sanfoundry”?
#include<stdio.h>
#define NL '\n'
main()
{
void f(void);
printf("enter the word\n");
f();
}
void f(void)
{
char c;
if((c=getchar())!=NL)
{
f();
printf("%c",c);
}
return;
}
a) sanfoundry
b) infinite loop
c) yrdnuofnas
d) fnasyrdnuo
47. Choose a correct statement about Recursive Function in C language.
A) Each recursion creates new variables at different memory locations
B) There is no limit on the number of Recursive calls
C) Pointers can also be used with Recursion but with difficulty.
D) All the above
48. How many functions are required to create a recursive functionality?
A) One
B) Two
C) More than two
D) None of the above
49. A recursive function without If and Else conditions will always lead to?
A) Finite loop
B) Infinite loop
C) Incorrect result
D) Correct result
50. A recursive function can be replaced with __ in c language.
A) for loop
B) while loop
C) do while loop
D) All the above
51. What is the output of C Program with Recursive Function.?
int mul(int);
int main()
{
int b;
b = mul(3);
printf("%d", b);
}
int mul(int x)
{
if(x<=1)
return 1;
return (x * mul(x-1));
}
A) 2
B) 3
C) 6
D) 1
52. What is the output of C Program with recursive function.?
int sum(int);
int main()
{
int b;
b = sum(4);
printf("%d", b);
}
int sum(int x)
{
int k=1;
if(x<=1)
return 1;
k = x + sum(x-1);
return k;
}
A) 10
B) 11
C) 12
D) 15
53. What is the output of C Program with functions.?
void show();
int show();
int main()
{
printf("ANT\n");
return 0;
}
void show()
{
printf("Integer") ;
}
int show()
{
printf("Void");
}
A) ANT
B) Integer
C) Void
D) Compiler error
54. What is the output of C Program with functions.?
void show(int);
void show(float);
int main()
{
printf("ANT\n");
return 0;
}
void show(int a)
{
printf("Integer") ;
}
void show(float b)
{
printf("Void");
}
A) Integer Void
B) ANT Integer Void
C) ANT
D) Compiler error
55. What is the output of C Program with functions.?
#include
int sum(int,int);
int main()
{
int a=5, b=10, mysum;
mysum = sum(a,b);
printf("SUM=%d ", mysum);
printf("SUM=%d", sum(10,20));
return 0;
}
int sum(int i, int j)
{
return (i+j);
}
A) SUM=15 SUM=30
B) SUM=30 SUM=15
C) SUM=15 SUM=15
D) SUM=30 SUM=30
56. Arguments passed to a function in C language are called ___ arguments.
A) Formal arguments
B) Actual Arguments
C) Definite Arguments
D) Ideal Arguments
57. Arguments received by a function in C language are called ___ arguments.
A) Definite arguments
B) Formal arguments
C) Actual arguments
D) Ideal arguments
58. Choose a non Library C function below.
A) printf()
B) scanf()
C) fprintf()
D) printf2()
59. What do you call this C Function calling itself.?
int funny2()
{
funny2(num);
}
A) Indefinite Function
B) Definite Function
C) Cursive Function
D) Recursive Function
60. What is the output of C Program with functions.?
int bunny(int,int);
int main()
{
int a, b;
a = bunny(5, 10);
b = bunny(10, 5);
printf("%d %d", a, b);
return 0;
}
int bunny(int i, int j)
{
return (i, j);
}
A) 5 10
B) 10 5
C) 5 5
D) Compiler error
61. How many values can a C Function return at a time?
A) Only One Value
B) Maximum of two values
C) Maximum of three values
D) Maximum of 8 values
62. What is the output of C Program with functions?
void main()
{
int a;
printf("TIGER COUNT=");
a=show();
printf("%d", a);
}
int show()
{
return 15;
return 35;
}
A) TIGER COUNT=15
B) TIGER COUNT=35
C) TIGER COUNT=0
D) Compiler error
63. What are types of Functions in C Language?
A) Library Functions
B) User Defined Functions
C) Both Library and User Defined
D) None of the above
64. What is the output of C program with functions.?
int show();
void main()
{
int a;
a=show();
printf("%d", a);
}
int show()
{
return 15.5;
return 35;
}
A) 15.5
B) 15
C) 0
D) Compiler error
65. What is the output of C Program.?
int myshow(int);
void main()
{
myshow(5);
myshow(10);
}
int myshow(int b)
{
printf("Received %d, ", b);
}
A) Received 5, Received 10,
B) Received 10, Received 5,
C) Received 0, Received 0,
D) Compiler error
66. What is the output of C Program with functions and pointers.?
int myshow(int);
void main()
{
int a=10;
myshow(a);
myshow(&a);
}
int myshow(int b)
{
printf("Received %d, ", b);
}
A) Received 10, Received 10,
B) Received 10, Received RANDOMNumber,
C) Received 10, Received RANDOMNumber, with a compiler warning
D) Compiler error
67. What is the output of C Program with functions and pointers.?
void myshow(int *);
void main()
{
int a=10;
printf("%d ", a);
myshow(&a);
printf("%d", a);
void myshow(int *k)
{
*k=20;
}
A) 10 10
B) 20 20
C) 10 20
D) Compiler error
68. What is the output of C Program with functions?
void myshow(int);
void main()
{
int a=10;
printf("%d ", a);
myshow(a);
printf("%d", a);
void myshow(int k)
{
k=20;
}
A) 10 10
B) 20 20
C) 10 20
D) Compiler error
69. Choose correct statements about C Language Pass By Value.
A) Pass By Value copies the variable value in one more memory location.
B) Pass By Value does not use Pointers.
C) Pass By Value protects your source or original variables from changes in outside functions or
called functions.
D) All the above
70. What is the output of C Program with functions?
main()
{
int i = abc(10);
printf("%d", --i);
}
int abc(int i)
{
return(i++);
}
A. 10
B. 9
C. 11
D. None of these.
71. void can be used
A. as a data-type of a function that returns nothing to its calling environment
B.inside the brackets of a function that does not need any argument
C.in an expression
D.both (a) & (b)
72. What is the output of C Program with functions?
main ()
{ int a = 4;
change { a };
printf ("%d", a);
}
change (a)
int a;
{
printf("%d", ++a);
}
A.55
B.45
C.54
D.44
73. What is the output of C Program with functions?
main()
{
inc(); inc(); inc();
}
inc()
{
static int x;
printf("%d", ++x);
}
A.prints 012
B.prints 123
C.prints 3 consecutive, but unpredictable numbers
D.prints 111
74. Running out of memory may occur due to
A.Non-recursive call
B.Recursive function call
C.Use of more extern variable
D.None of these
75. When a function is recursively called, all automatic variables
A.Are initialized during each execution of the function
B.Are retained from the last execution
C.Are maintained in a queue
D.None of these