• Courses
  • Tutorials
  • Jobs
  • Practice
  • Contests

C Loops & Control Structure

Question 31

What would happen when we compile and run this program?
C
<br>
#include < stdio.h ><br>
int main()<br>
{<br>
  int i; <br>
  goto LOOP;<br>
  for (i = 0 ; i < 10 ; i++)<br>
  {<br>
     printf(\"GeeksQuiz &#92;n\");<br>
     LOOP:<br>
      break;<br>
  }<br>
  return 0;<br>
}<br>

  • No compile error and it will print GeeksQuiz 10 times because goto label LOOP wouldn’t come in effect.
  • No compile error and it’ll print GeeksQuiz only once because goto label LOOP would come in picture only after entering for loop.
  • Compile Error because any goto label isn’t allowed in for loop in C.
  • No compile error but behaviour of the program would depend on C compiler due to nondeterministic behaviour of goto statement.
  • No compile error and it will not print anything.

Question 32

A typical “switch” body looks as follows:
C
<br>
switch (controlling_expression)<br>
{<br>
  case label1:<br>
    /*label1 statements*/<br>
    break;<br>
  case label2:<br>
    /*label1 statements*/<br>
    break;<br>
  default:<br>
    /*Default statements*/<br>
}<br>

Which of the following statement is not correct statement?
  • “switch” body may not have any “case” label at all and it would still compile.
  • “switch” body may not have the “default” label and it would still compile.
  • “switch” body may contain more than one “case” labels where the label value of these “case” is same and it would still compile. If “switch” controlling expression results in this “case” label value, the “case” which is placed first would be executed.
  • “switch” body may not have any “break” statement and it would still compile.
  • “switch” body can have the “default” label at first i.e. before all the other “case” labels. It would still compile.

Question 33

Which of the following is correct with respect to “Jump Statements” in C?
  • goto
  • continue
  • break
  • return
  • All of the above.

Question 34

Consider the following program fragment
if(a > b)
if(b > c)
s1;
else s2;
s2 will be executed if
  • a <= b
  • b > c
  • b >= c and a <= b
  • a > b and b <= c

Question 35

Consider the following program fragment i=6720; j=4; while (i%j)==0 { i=i/j; j=j+1; } On termination j will have the value
  • 4
  • 8
  • 9
  • 6720

Question 36

The output of the following program is
main()
{
static int x[] = {1,2,3,4,5,6,7,8}
int i;
for (i=2; i<6; ++i)
x[x[i]]=x[i];
for (i=0; i<8; ++i)
printf("%d", x[i]);
} 

  • 1 2 3 3 5 5 7 8
  • 1 2 3 4 5 6 7 8
  • 8 7 6 5 4 3 2 1
  • 1 2 3 5 4 6 7 8

Question 37

The for loop
for (i=0; i<10; ++i)
printf("%d", i&1);
prints:
  • 0101010101
  • 0111111111
  • 0000000000
  • 1111111111

Question 38

In C++, which system - provided function is called when no handler is provided to deal with an exception?
  • terminate ( )
  • unexpected ( )
  • abort ( )
  • kill ( )

Question 39

What is the output of the following C code?
#include 
int main()
{
int index;
for(index=1; index<=5; index++)
{
printf("%d", index);
if (index==3)
continue;
}
}

  • 1245
  • 12345
  • 12245
  • 12354

Question 40

Consider the following C code segment:
#include 
main()
{
    int i, j , x ;
    scanf("%d", &x);
    i = 1 ; j = 1;
    while ( i< 10 ) {
          j = j * i;
          i = i + 1;
          if (i == x) break ;
          }
 }
For the program fragment above, which of the following statements about the variables i and j must be true after execution of this program? [!(exclamation) sign denotes factorial in the answer]
  • ( j = (x - 1 )! ) ? (i >= x)
  • ( j = 9!) ? (i =10)
  • (( j = 10!) ? (i = 10 )) V (( j = (x - 1)!) ? (i = x ))
  • (( j = 9!) ? (i = 10)) V (( j = (x - 1)!) ? (i = x ))

There are 45 questions to complete.

Last Updated :
Take a part in the ongoing discussion