+ 1
What is the output of this code?
int i=1; for (; i < 100; i++) { if ( i > 5) continue; i *=i; } cout << i; Select correct one? A. 99 B.100 C.25 D.26
2 Answers
0
Here's a debug version of the code (with printf's in the right place)
#include <stdio.h>
int main() {
int i=1;
printf("A:%d\n", i);
for (; i < 100; i++) {
printf("B:%d\n", i);
if (i > 5) continue;
{
i *=i;
printf("C:%d\n", i);
}
printf("D:%d\n", i);
}
printf("E:%d\n", i);
}
Here's the output from the debug code:
A:1
B:1
C:1
D:1
B:2
C:4
D:4
B:5
C:25
D:25
B:26
B:27
B:28
B:29
B:30
B:31
B:32
B:33
B:34
B:35
B:36
B:37
B:38
B:39
B:40
B:41
B:42
B:43
B:44
B:45
B:46
B:47
B:48
B:49
B:50
B:51
B:52
B:53
B:54
B:55
B:56
B:57
B:58
B:59
B:60
B:61
B:62
B:63
B:64
B:65
B:66
B:67
B:68
B:69
B:70
B:71
B:72
B:73
B:74
B:75
B:76
B:77
B:78
B:79
B:80
B:81
B:82
B:83
B:84
B:85
B:86
B:87
B:88
B:89
B:90
B:91
B:92
B:93
B:94
B:95
B:96
B:97
B:98
B:99
E:100
The answer is 100, i.e. B
+ 2
B. 100