+ 1
int main () { int a[3] = {2,7,3}; for (int i=0; i<3; i++){ a[i]-=i; } cout<<a[i]; }
Can someone explain how the answer is 6?
6 Antworten
+ 4
since i's scope is lost it should show error, but since you asked how 6,---
when first iteration is executed, i=0, the first number( a[0] ) 2 is deducted by 0, second iteration second number ( a[1])7 gets deducted by 1(i ), next iteration is not executed as i is greater than 2 now. hence now i=1 only hence prints second number a[1]
+ 1
This should actually throw an compilation error. The scope of i ends with the for loop and in the next statement, i is not a valid variable.
0
Showing error😕
0
That curly brace above cout should come after cout ryt???
0
The answer is then 261
- 1
like it