in DS
542 views
0 votes
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);
    }
}
in DS
542 views

4 Comments

thanks i missed that point
0
0

But in Dev C compiler, I am getting *(p-1) as 0 , not able to understand why 

0
0
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

1 Answer

0 votes
0 votes
The output should be -->

1 2 3 4

1 garbage-value garbage-value garbage-value

Related questions