Nested pointers and references

4

I have a question in interpreting (in the form I read my code) in assignments in pointers in the C language.

I did not understand the logic of the following assignments:

"If i and j are integer variables and p and q pointers to int , which of the following attribution expressions are illegal?"

Statement of the exercise:

a) p = &i;
b) *q = &j;
c) p = &*&i; 
d) i = (*&)j;
e) i = *&j;
f) i = *&*&j;
g) q = *p;
h) i = (*p)++ + *q;

I have questions on items C, D, E and F, since I did not understand the logic of the following assignments ... A, B, G and H I have no doubt in the assignments, only those using "* & var ".

How do I interpret these assignments in C?

    
asked by anonymous 06.09.2015 / 19:13

1 answer

2

It's not much of a secret if you know how * and & works by itself.

  • C) get the address of i , then get the content of this address (which is obviously the value of i ) and then get the address of this content and save it in p .
  • D) This syntax is not possible
  • E) Get the address of j and then get the contents of this address to save in i .
  • F) Get the address of j , get the contents of this address and get the address of it and finally get the contents of this address to save in i .

Interpretation depends on precedence and associativity of operators.

This is for demonstration purposes only. It does not make sense to do this kind of thing. At least not this way.

    
06.09.2015 / 19:42