JOIN ADRE 2.0 Telegram Group

Functions in C Programming - MCQ Questions and Answers

Questions
1 Consider the following program:

	main()
	{
		char *x="xyz;
		f(k);
		printf("%s\n",k);
	}
	f(char *k)
	{
		k=malloc(4);
		strcpy(k,"pq");
	}
	

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;
	}
	main()
	{
		int i=3;
		i=func(i);
		i=func(i);
		printf("%d", i);
	}
	
A 3
B 1
C 0
D 2

Answer: Option [B]

mcq on c programming functions 02

Advertisement
ADRE 2.0 Mock Test - 5 Start Test
ADRE 2.0 Mock Test - 5 Start Test

DOWNLOAD CURRENT AFFAIRS PDF FROM APP

3 What is wrong with the following function?

	int Main(int ac, char *av[])
	{
		if(ac==0) return 0;
		else
	{
	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?

	main()
	{
		int a=1, b=10;
		swap(a,b);
		printf("\n%d%d", a,b);
	}
	swap(int x, int y)
	{
		int temp;
		temp=x;
		x=y;
		y=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.

ADRE 2.0 MOCK TEST

Take Mock Tests

Government Schemes Mock Test Start Test!
Political Science Mock Test – 42 Start Test
History Test – 190 Start Test
Quantitative Aptitude Test Start Test!
Trigonometry - Mock Test Start Test!
Data Interpretation - Mock Test Start Test!
General Awareness - Mock Test Start Test!
Reasoning Ability - Mock Test Start Test!
Englist(Antonyms) Mock Test 1 Start Test!
Quantitative Aptitude (Percentage) Mock Test Start Test!
Economy Mock Test 1 Unlock Test!
Books & Authors - Test 2 Unlock Test!

Chapters

Advertisement