0 0 votes what wiill be the output? #include<stdio.h> void main() { int x; int a[] = {1, 2, 3, 4}; int *p = a; for(int i=0; i<=3; i++) { x = *(p+i); printf("%d ",x); } printf("\n"); for(int i=0;i<=3; i++) { x= *(p-i); printf("%d ", x); } } Data Structures + – Lone Wolf 1.3k views answer comment Share Follow Print See all 6 Comments 6 6 Comments reply Shaik Masthan commented Aug 21, 2018 reply Follow flag x= *(p-i); p at base address only...... this statement looks as wild pointer 0 0 replyShare Lone Wolf commented Aug 21, 2018 reply Follow flag should'nt p be at last element of array 0 0 replyShare arvin commented Aug 21, 2018 reply Follow flag no u are incrementing p but u are storing that value in x which is changing every time with loop. so value of p reamins same so answer should be. 1,2,3,4 1, garbage, garbage,garbage 2 2 replyShare Lone Wolf commented Aug 21, 2018 reply Follow flag thanks i missed that point 0 0 replyShare Sayan Bose commented Aug 21, 2018 reply Follow flag But in Dev C compiler, I am getting *(p-1) as 0 , not able to understand why 0 0 replyShare arvin commented Aug 21, 2018 reply Follow flag i too ran this on online compiler its coming 0. i think maybe because of some property or criteria. because we cannot track *(p-1) . 0 0 replyShare Please log in or register to add a comment.
0 0 votes The output should be --> 1 2 3 4 1 garbage-value garbage-value garbage-value rtiwari95 answered Aug 21, 2018 rtiwari95 comment Share Follow 0 reply Please log in or register to add a comment.