what is the output of this code and how?? | Sololearn: Learn to code for FREE!
New course! Every coder should learn Generative AI!
Try a free lesson
+ 2

what is the output of this code and how??

int arr[3]={40,41,42}; int *ptr=(int*)(&arr+1); printf("%d %d", *(arr+1) , *(ptr-1));

5th Jan 2022, 12:34 PM
Nariman Tajari
Nariman Tajari - avatar
9 Answers
+ 2
Error cause you try to print a number but a pointer is supplied.
5th Jan 2022, 12:55 PM
Slick
Slick - avatar
+ 1
Cause of the ampersand '&' here is expected output: https://code.sololearn.com/c1qq2eHR9ZP4/?ref=app
5th Jan 2022, 5:55 PM
Slick
Slick - avatar
+ 1
Martin Taylor the code he supplied outputs 41 42. When i removed the ampersand it gave expected output. I think he wants to know why
5th Jan 2022, 8:53 PM
Slick
Slick - avatar
0
Slick you are right and i ve edited this code, now what is the output
5th Jan 2022, 1:08 PM
Nariman Tajari
Nariman Tajari - avatar
0
Tell me what the output is please
5th Jan 2022, 5:22 PM
Slick
Slick - avatar
0
41 42 Slick
5th Jan 2022, 5:47 PM
Nariman Tajari
Nariman Tajari - avatar
0
could you tell me how one find the *(ptr-1) as 42. Slick thanks
5th Jan 2022, 6:07 PM
Nariman Tajari
Nariman Tajari - avatar
23rd Jan 2022, 5:48 PM
Nariman Tajari
Nariman Tajari - avatar
- 1
VriddhiJain
7th Jan 2022, 10:14 AM
Vriddhi Jain