[C++] Need help with Pointers

veddotcom

Journeyman
CODE 1
void main()
{
int arr[]={11,12,13,14,15};

cout<<&&*arr; //this line gives Expression Syntax Error, WHY???????
}

CODE 2
void main()
{
int arr[]={11,12,13,14,15};

cout<<&(&*arr); //this line gives Lvalue Required Error, WHY???????
}

What i m thinking....may be i m wrong :D
FIRST Error
I guess two && operator is not allowed Consecutively becuase this may Conflict with logical operator &&

Second Error
I don't have any clue why i m getting Lvalue Error...How i m suppose to to change the contact value(by putting just braces) stored in "arr"..


Guide me...Thank You.
 
Last edited:
OP
veddotcom

veddotcom

Journeyman
Re: Need Help With This C Code...

Second Error:
it says "The & (address) operator yields a pointer to its operand. The operand must be an lvalue, a function designator, or a qualified name. It cannot be a bit field, nor can it have the storage class register"

I didn't understand why the (&*arr) is not Lvalue but &arr OR &(arr) is...

Also if you will put the code &(*&arr) instead of &(&*arr), the program runs well....
 
Re: Need Help With This C Code...

Second Error:
it says "The & (address) operator yields a pointer to its operand. The operand must be an lvalue, a function designator, or a qualified name. It cannot be a bit field, nor can it have the storage class register"

I didn't understand why the (&*arr) is not Lvalue but &arr OR &(arr) is...

Also if you will put the code &(*&arr) instead of &(&*arr), the program runs well....

& = address of operator
* = value of operator

address is absolute and cannot be referenced. address of address [&(&)] is not valid

&(*&arr)= address of ( value of (address of) )
it is same as "&arr"

&(&*arr)= address of ( address of (value of))
incomputable rvalue and hence operator cannot put result to lvalue

if u still dont get it go through Pointers
 

Liverpool_fan

Sami Hyypiä, LFC legend
Re: Need Help With This C Code...

Let's make an analogy.
Suppose A = YOU.
Now &A = Your Address.
If & mean address of, so whatever is passed to it, it returns it's address.
Now if you say &(&A), it means return the address of &A. Which practically means:
Return the Address of the Address of A. Does that make any sense? You can have your home address where you reside, but does your home address have an address where it lives?
I hope I made it clear.
 
T

The Conqueror

Guest
Re: Need Help With This C Code...

Misleading Title. This is NOT a C Code. It is infact a C++ Code .
 
Top Bottom