Thursday, 26 May 2011

C program part2

1.Can comments be nested?

Not in standard (K&R) C.
2.From the standpoint of programming logic, what is the difference between a loop with the test at the top, and a loop where the test is at the bottom?

If the test is at the bottom, the body of the loop will always be executed at least once. When the test is at the top, the body of the loop may never be executed.
3.Specify the skeletons of two C loops with the test at the top.
next = 0; /* setup */

while ( next < max) { /* test */
printf("Hello "); /* body */
next++; /* update */
}


and


for ( next = 0; next < max; next++) /* setup,test */
/* and update */
printf("Hello"); /* body */
4.Specify a C loop with the test at the bottom.



next = 0; /* setup */ do { printf("Hello"); /* body */ next++; /* update */ } while ( next < max); /* test */
5.What is the switch statement?
It is C's form of multiway-conditional (a.k.a case statement in Pascal).

No comments:

Post a Comment