+ 2

This question ask in c++ quiz. "What is output of this code (<array> included) ?"

https://code.sololearn.com/c2l65KXVK06g/?ref=app

6th Feb 2018, 1:08 PM
Gajendra Parmar
Gajendra Parmar - avatar
16 Answers
+ 18
<array> header file should be included. In question it is said that assume it to be included check this out 👇 now it will work https://code.sololearn.com/cPKD1Ngq8FTX/?ref=app
7th Feb 2018, 7:45 AM
🌛DT🌜
🌛DT🌜 - avatar
+ 14
the answer will be 9 int main() { array<int,5>arr={0,2,1,3,5}; int *x; // declaration of a pointer x... x=&arr[3]; //pointer x is pointed to arr[3] therefore the value of *x becomes 3 ( *x=3) *x+=5; // *x=*x+5=8 ..... as pointer x is pointing to arr[3] with & operator as value of *x changes value of arr[3] also changes ... so now arr[3]=8... cout<<arr[3]+arr[2]; // 8+1 = 9 return 0; }
7th Feb 2018, 7:07 AM
🌛DT🌜
🌛DT🌜 - avatar
+ 1
The code has some errors: 0) x*+=5 is an invalid operation. It should be *x+=5. 1) x[3] points to arr+6, which is an invalid location and has no data at all. So it will return a random value. So maybe the challenge was wrong? Just mark it with a wrong answer.
6th Feb 2018, 1:40 PM
Solo Wanderer 4315
Solo Wanderer 4315 - avatar
+ 1
i had checked I had taken photo also.
6th Feb 2018, 2:12 PM
Gajendra Parmar
Gajendra Parmar - avatar
6th Feb 2018, 4:01 PM
Gajendra Parmar
Gajendra Parmar - avatar
+ 1
screen shot not possible in sololearn but if you provide your email id then I will send.
6th Feb 2018, 4:08 PM
Gajendra Parmar
Gajendra Parmar - avatar
+ 1
This question ask in c++ quiz. "What is output of this code (<array> included) ?" https://code.sololearn.com/c2l65KXVK06g/?ref=app
7th Feb 2018, 4:47 AM
Gajendra Parmar
Gajendra Parmar - avatar
+ 1
https://drive.google.com/file/d/1CeUbbH9xfxk2RyWOhrv_rBFiE-4INZPD/view?usp=drivesdk
7th Feb 2018, 5:16 AM
Gajendra Parmar
Gajendra Parmar - avatar
+ 1
above link is the screen shot
7th Feb 2018, 6:06 AM
Gajendra Parmar
Gajendra Parmar - avatar
+ 1
why this program is not run in sololearn
7th Feb 2018, 7:08 AM
Gajendra Parmar
Gajendra Parmar - avatar
+ 1
thank you
7th Feb 2018, 7:59 AM
Gajendra Parmar
Gajendra Parmar - avatar
0
this the code ask in c++ solo learn quiz and when I run this code I got error, so what we consider it's output " no output" or any other ?
6th Feb 2018, 4:06 PM
Gajendra Parmar
Gajendra Parmar - avatar
0
can any one help me about this quiz question ? I am waiting.
7th Feb 2018, 4:47 AM
Gajendra Parmar
Gajendra Parmar - avatar
0
This question ask in c++ quiz. "What is output of this code (<array> included) ?" https://code.sololearn.com/c2l65KXVK06g/?ref=app
7th Feb 2018, 6:06 AM
Gajendra Parmar
Gajendra Parmar - avatar
0
https://drive.google.com/file/d/1CeUbbH9xfxk2RyWOhrv_rBFiE-4INZPD/view?usp=drivesdk
7th Feb 2018, 6:06 AM
Gajendra Parmar
Gajendra Parmar - avatar
0
@DT That was x[3] + x[2], which you replaced with arr[3] + arr[2], and thats what corrected the code. But I don't know what was in the challenge though.
7th Feb 2018, 12:19 PM
Solo Wanderer 4315
Solo Wanderer 4315 - avatar