edited by
392 views
3 votes
3 votes

Assume that $a[4]$ is a one-dimensional array of $4$ elements, $p$ is a pointer variable and $p = a$ is performed. Now, which among these expressions is illegal?

  1. $p == a[0]$
  2. $p == \&a[0]$
  3. $^*p == a[0]$
  4. $p[0] == a[0]$
edited by

1 Answer

Best answer
2 votes
2 votes


p is a pointer variable it means int *p;

after that p=a;

  • statement 1)p==a[0]


p is holding address and a[0] is holding value how this can be done . // This is illegal

  • statement 2)

p==&a[0]

p==&*(a+0)

p==a(both are holding address)

  • statement 3) *p ==a[0]

both are holding 1st value of array a .

  • statement 4) p[0]==a[0] same as previous


Therefore  statement 2,3,4 is right

answer is option A .

selected by
Answer:

Related questions

0 votes
0 votes
1 answer
1
Bikram asked May 14, 2017
351 views
Spot the error(s) in this code snippet :int n=2; // Line 1 switch(n) { case 1.5: printf( "gate"); break; case 2: printf( "overflow"); break; case 'A': printf("gateoverflo...
0 votes
0 votes
1 answer
2
Bikram asked May 14, 2017
199 views
#include<stdio.h int K = 10; int main() { foo(); foo(); return 0; } int foo() { static int k= 1; printf("%d ",k); k++; return 0; }What is the output of the above code sni...
0 votes
0 votes
1 answer
3
Bikram asked May 14, 2017
202 views
What is the output of the following program? int fun (int z) { if( z==0 || z==1 ) return 1; else return fun(z-1) ; } int main() { int y; y=fun(8); printf(“%d”...
2 votes
2 votes
1 answer
4
Bikram asked May 14, 2017
694 views
What is the output of the below mentioned code snippet?#include <stdio.h int main() { int i=10; static int x=i; if(x==i) printf("Equal"); else if(x>i) printf("Greater"); ...