+ 2

Hey friends !please explain me this code and say why out put is 23?

include <iostream> using namespace std; int main() { int a[3]={1,2,3}; for(int i=1;i<=2;i++) cout<<a[i]; return 0; } //output is 23 ?

24th Aug 2018, 5:38 PM
Albert Whittaker :Shaken To Code
Albert Whittaker :Shaken To Code - avatar
4 Antworten
+ 2
a[0] = 1 a[1] = 2 a[2] = 3 Using for loop you are printing second and third element of array that is a[1] , a[2]. Hope this helps ☺️☺️.
24th Aug 2018, 5:52 PM
Meet Mehta
Meet Mehta - avatar
+ 4
This loop will be executed twice only in the first time will print 2 and the second time 3 Clarification: cout<<a[1]//output:2 cout<<a[2]//output:3 The matrix will begin printing from the second element with the index 1
24th Aug 2018, 5:55 PM
Ammar Moulla
Ammar Moulla - avatar
0
cin>> [i];
6th Sep 2018, 7:44 PM
Mira khan
0
Array index begin from 0, so you start the loop from the second element.
18th Jul 2019, 11:03 AM
Badreddine Deneche
Badreddine Deneche - avatar