Q5 1-7 Flashcards

1
Q

/* 1 What output does the following program fragment produce? i = 1; while (i { printf (“%d “, i ); i *= 2; } */

A

1 2 4 8 16 32 64 128

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
2
Q

/* 2 What output does each of the following two statements produce? Statement 1: for (i = 5, j = i – 1; i > 0; –i, j = i - 1) printf(“%d %d”, i, j); Statement 2: for (i = 5, j = i – 1; i > 0, j > 0; –i, j = i - 1) printf(“%d %d”, i, j); */

A

Statement 1: 5 44 33 22 11 0 Statement 2: 5 44 33 22 1

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
3
Q

/* 3 Which one of the following statements is not equivalent to the other two (assuming that the loop bodies are the same)? • while (i < 10) {…} • for (; i < 10;) {…} • do {…} while (i < 10) ; */

A

do while, because do while will always iterate at least once (checks the condition after one iteration)

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
4
Q

/* 4 What output does the following for statement produce? for (i = 10; i >= 1; i /= 2) printf(“%d “, –i); */

A

9 3 0

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
5
Q

/* 5 What output does the following for statement produce? for (i = 10; i >= 1; i %= 2) printf(“%d “, i++); */

A

10 1

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
6
Q

/* 6 What output does the following for statement produce? for (i = 10; i >= 1; i *= 2) printf(“%d “, (i-=6)); */

A

4 2 -2

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
7
Q

/* 7 What output does the following for statement produce? for (i = 10; i >= 1; i -= 1) printf(“%d “,(i/=2)); */

A

5 2 0

How well did you know this?
1
Not at all
2
3
4
5
Perfectly