edited by
361 views
1 votes
1 votes
#include<stdio.h>
main() {
  int a[]={2,4,6,8,10,12,14,16,18,20};
  int b=7;
  printf("%d\n",*&b); // Prints value at the address of b  ie '7'
  printf("%u\n",&a);   // Prints address of a[0]. ie &a points to a[0] which is '2'.
  printf("%u\n",*a);   // Prints '2'
  printf("%u\n",*&a); // Why it does not print '2'  (ie value at the address of a).
}
edited by

3 Answers

2 votes
2 votes

From c Precedence table -:http://www.difranco.net/compsci/C_Operator_Precedence_Table.htm

your doubt can be simplified to 

(Associativity right to left)

printf("%d\n",*(&a));

Array a always points to the Address of the First element of the Array.

 printf("%d\n",a);//It will print address of first element of a.
 printf("%d\n",*a);//prints value at" Address of first element of array" 
 printf("%d\n",&a);//prints the address of "address of first element of array".
 printf("%d\n",*(&a));//prints the value at address of "address of first element of array"->which implies address of first element of array
printf("%d\n",*(*(&a)));//prints the value at (value at address of "address of first element of array"->which implies address of first element of array) which is 2
1 votes
1 votes
1. a is the name of the array. It decays to a pointer to the first element of the array of type int *
2. &a is the address of the entire array object. It's a pointer of type int(*)[]
3. *(&a) dereferences back to a ; which is of type int* pointing to the first element of array.
1 votes
1 votes

*& signifies the receiving the pointer by reference. It is not like you actually fetch the vakue at address. It fetches the address only.

#include <stdio.h>

int main() {
	
    int a[]={2,4,6,8,10,12,14,16,18,20};
    int b=7;
    int *p = &a;
    
    printf("%d\n", *&b); // Prints value at the address of b.
    printf("%u\n", &a);  // Prints address of a[0]. 
    printf("%u\n", *a);  // Prints '2'
    printf("%d\n", *p);  // Prints '2'
    
    return 0;
}

Where as the above prints the value 2.

Related questions

0 votes
0 votes
0 answers
4
Ishan asked May 26, 2017
464 views
How many bit strings of length eight contain either three consecutive 0s or four consecutive 1s?