Functions in C Programming - MCQ Questions and Answers

1 Consider the following program:

		char *x="xyz;
	f(char *k)

What will be the output?

A pq
B xyz
C syntax error
D none of these

Answer: Option [C]

There is an opening quote in the third statement but no closing. So syntax error occurs.

mcq on c programming functions 01

2 What does the following function print?

	func(int i)
		if(i%2) return 0;
		else return 1;
		int i=3;
		printf("%d", i);
A 3
B 1
C 0
D 2

Answer: Option [B]

mcq on c programming functions 02

3 What is wrong with the following function?

	int Main(int ac, char *av[])
		if(ac==0) return 0;
	printf("%s", av[ac-1]);
	Main(ac-1, av);
		return 0;
A Function cannot have name as Main, it should be main only
B The arguments' name must be argc and argv, respectively
C There cannot be two return statements in the function
D There error in the function

Answer: Option [D]

There is no error in the function. Here the Main() function differenciate with the main(). In the given problem the Main() has two arguments as int ac, char *av[]

4 What is the following function determining?

	int fn(int a, int b)
		if (b==0) return 0;
		if (b==1) return a;
		return a+fn(a, b-1);
A a+b where a and b are integers
B a+b where a and b are non-negative integers
C a*b where a and b are integers
D a*b where a and b are non-negative integers

Answer: Option [B]

The above function is a recursive function. The function will return a+b where a and b are non-negative integers

5 What is the output of the following code?

		int a=1, b=10;
		printf("\n%d%d", a,b);
	swap(int x, int y)
		int temp;
A 1 1
B 1 10
C 10 1
D None of these

Answer: Option [B]

The 'call by value' method is applied in this program. Here the data is passed by value in the main(). So the variables are not changed.


current affairs 2021 pdf plan

Current Affairs MCQs

State-wise Current Affairs

Month-wise Current Affairs 2021

Category-wise Current Affairs

Jobs by Qualification

Free Mock Test