What is the output of the following C code int alpha5 2 4 6
What is the output of the following C++ code? int alpha[5]- (2, 4, 6, 8,10); int j; cout
Solution
The output of the above code : 10 8 6 4 2
the statement int alpha[5]={2,4,6,8,10}
Array
Alpha
Value
2
4
6
8
10
Index
0
1
2
3
4
Initial value of j is 4
j>=0 i.e 4>=0, true
cout << alpha[j] i.e alpha[4]
10
j--, ie j value is 3
j>=0 i.e 3>=0, true
cout << alpha[j] i.e alpha[3]
8
j--; i.e j value is 2
j>=0 i.e 2>=0, true
cout << alpha[j] i.e
alpha[2]
6
j--; i.e j value is 1
j>=0; i.e 1>=0, true
cout << alpha[j] i.e alpha[1]
4
j--; i.e j value is 0
j>=0 i.e 0>=0; ture
cout << alpha[j] i.e alpha[0]
2
j--; i.e; j value is -1
j>=0; i.e -1>=0; false
| Array Alpha | Value | 2 | 4 | 6 | 8 | 10 |
| Index | 0 | 1 | 2 | 3 | 4 |