Menu Close

C exam on Loops

Please enter your email:

1.

Output of following code?

#include<stdio.h>
int main()
{
  int i=30 ;
  while(i>0)
  {
    printf("%d", i%=5);
  }
  return 0;
}

 

 
 
 
 

2.

Output of following code?

#include<stdio.h>
int main()
{
  unsigned short int a = 25;
  while(a++)
  {

  }
  printf("%d ", ++a);
  return 0;
}

 

 
 
 
 

3.

Output of following code?

#include<stdio.h>
int main()
{
  signed char ch=125;
  while(ch++>0)
  {
    printf("%d ",++ch);
  }
  return 0;
}

 

 
 
 
 

4.

Output of following code?

#include<stdio.h>
int main()
{
  int i;
  for(i=1 ; i<=20 ; i++)
  {	
    switch(i)
    {
      case 0 	: i+=5;
      case 1 	: i+=4;
      case 2 	: i+=3;
      case 3 	: i+=2;
      default	: i+=4;
          break;	
    }
    printf("%d ",i);
  }
  return 0;
}

 

 
 
 
 

5.

Output of following code?

#include<stdio.h>
int main()
{
  int s=0;
  while(s++ <= 10)
  {
    if(s<4 && s<8)
      continue;
    printf("%d ", s);
  }
}

 

 
 
 
 

6.

Output of following code?

#include<stdio.h>
int main()
{
  int i=0, j=0;
  while(++i<=5)
    while(++j<=5)
      printf("%d ",j);
  
  printf("%d ",j);
  return 0;
}

 

 
 
 
 

7.

Output of following code?

#include<stdio.h>
int main()
{
  int i=0;
  for(i=-1 ; i<=11 ; i++)
  {
    if(i<5)
      continue;
    else
      break;
    printf("i : %d\n",i);
  }
  return 0;
}

 

 
 
 
 

8.

Output of following code?

#include<stdio.h>
int main()
{
  int a=3,b=3;
  while(--a && --b);
  printf("%d, %d", a, b);
  return 0;
}

 

 
 
 
 

9.

Infinite looping cannot be avoided by

 
 
 
 

10.

Output of following code?

#include<stdio.h>
int main()
{
  int a = 4;
  while(a++ + 2 <= 12)
  {
    printf("%d " , a++ + 2);
  }
  return 0;
}

 

 
 
 
 

Question 1 of 10