MC logo

Control Constructs

  Practice Questions

What is printed by each of the following?

  1.           int m;
              for (m = 0; m < 5; m++)
              {
                   if(m == 3) continue;
                   printf("Line %d\n", m);
              }
    

  2.           int m;
              m = 0;
              while (m < 5)
              {
                   if(m == 3) continue;
                   printf("Line %d\n", m);
                   m++;
              }
    

  3.           int m;
              m = 5;
              do
                   printf("Line %d\n", m);{
              while (m++ < 5)
    

  4.           int m = 7;
              switch(m)
              {
                   case 4: printf("Mike\n");
                   case 6: printf("Suzie\n");
                   case 7: printf("Arnold\n");
                   case 11: printf("Ann\n");
                   default: printf("Smith\n");
              }
    

  5.           enum {little, some, much, gobs = 1, national_debt} frank;
              frank = much;
              printf("%d %d\n", frank, frank == national_debt);
    

<<Assignment and Side Effects II Answer Pointers and Arrays>>