Home » Aptitude Questions and Answers » C Aptitude Questions and Answers

C for loop Aptitude Questions and Answers

This section contains Aptitude Questions and Answers on C language For Loops (with multiple answers) with explanation.
Submitted by Ashish Varshney, on February 17, 2018

List of C programming for loops Aptitude Questions and Answers

1) How many times this loop will execute?
int main()
{
	inti;
	for(i=0;i<10;i++)
	{
		printf("%d\n",i++);
		i=++i;
	}
	return 0;
}
  1. 10
  2. 5
  3. 4
  4. None of these

2) How many times this loop will execute?
const MAX=10;
int main()
{
	inti=1;
	for(;i<MAX;i=i/i)
	{
		printf("%d\n",i);
	}
	return 0;
}
  1. 10
  2. 5
  3. 4
  4. Infinite

3) How many times this loop will execute?
int main()
{
	int max = 5;
	inti = 0;
	for(;;)
	{
		i++;
		if(i> max)
			break;
		printf("i = %d\n",i);
	}
	return 0;
}
  1. 2
  2. 5
  3. 4
  4. None of these

4) What will be the output?
int main()
{
	int max = 5;
	int c = 0;
	for(; c <max;c++);
	{
		printf("%d ",c);
	}
	printf("END\n");
	return 0;
}
  1. 1 2 3 4 END
  2. 1 2 3 4 5 END
  3. 5 END
  4. Error

5) What will be the output?
int main()
{
	inti=5;
	for (; 0; i--)
	{
		printf("%d\n",i);
	}
	return 0;
}
  1. 54321
  2. No output
  3. Compile time error
  4. Run time error

6) How many times loop will be executed?
#include <stdio.h>

int main()
{
	int i,k;
	for (i=0, k=0; (i< 5 && k < 3); i++, k++)
	{
		;
	}
	printf("%d\n",i);
	
	return 0;
}
  1. 5
  2. 3
  3. 4
  4. No output







Comments and Discussions

Ad: Are you a blogger? Join our Blogging forum.





Languages: » C » C++ » C++ STL » Java » Data Structure » C#.Net » Android » Kotlin » SQL
Web Technologies: » PHP » Python » JavaScript » CSS » Ajax » Node.js » Web programming/HTML
Solved programs: » C » C++ » DS » Java » C#
Aptitude que. & ans.: » C » C++ » Java » DBMS
Interview que. & ans.: » C » Embedded C » Java » SEO » HR
CS Subjects: » CS Basics » O.S. » Networks » DBMS » Embedded Systems » Cloud Computing
» Machine learning » CS Organizations » Linux » DOS
More: » Articles » Puzzles » News/Updates


© https://www.includehelp.com some rights reserved.