C while loop Aptitude Questions and Answers

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

List of C programming for while Aptitude Questions and Answers

1) What will be the output in given input?

When, input: 'a' and 1

int main()
{
	int n,i=0;
	while(scanf("%d",&n)==1)
	{
		printf("END\n");
	}
	return 0;
}
  1. Runtime_error and Compile time error
  2. Compile time error and Runtime_error
  3. Syntax error and Syntax error
  4. No output and END

2) How many times above loop will execute?

int main()
{
	int n=10,i=0;
	while(1)
	{
		printf("END\n");
		n++;
	}
	return 0;
}
  1. 10
  2. 5
  3. 4
  4. Infinite

3) What is the value of 'n' after while loop executed?

int main()
{
	int n=0,a=5,b=10;
	while(n<=(a^b))
	{
		n++;
	}
	printf("%d",n);
	return 0;
}
  1. 15
  2. 16
  3. 10
  4. None of this.

4) What is the value of 'n' after while loop executed?

int main()
{
	int n=0,a=5,b=10;
	while(n<=(b<<a))
	{
		n++;
	}
	printf("%d",n);
}
  1. 64
  2. 256
  3. 321
  4. 320

5) What will be the output?

int main()
{
	int a=16,n=0;
	while(n<=~(~a))
	{
		n++;
	}
	a=n;
	printf("%d",~a);
	return 0;
}
  1. -18
  2. -17
  3. 18
  4. 17





Comments and Discussions!

Load comments ↻





Copyright © 2024 www.includehelp.com. All rights reserved.