Sunday, April 29, 2012

9.35

Test each of the following C/C++ code fragments with a translator of your choice (or rewrite it into another language and test it) and explain its behavior:

(a)
{
int i, n = 3;
for( i = 1; i <= n; i++)
{
printf("i = %d\n, i");
n = 2;
}

the loop runs twice and prints "i = 1" the first time through and "i = 2


(b)
int j;
for(j = 1; j <= 3; j++)
{
printf("j = %d\n", j);
j = 3;
}

it returns "j = 1", then exits the loop

No comments:

Post a Comment