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?
int main()
{
	inti,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






Was this page helpful? YES NO

Are you a blogger? Join our Blogging forum.



Comments and Discussions





© https://www.includehelp.com (2015-2018), Some rights reserved.




close Like other websites, this site uses cookies to deliver relevant ads based on your interest, by using our website, you acknowledge that you have read our privacy policy.