Forum     

Go Back   Digit Technology Discussion Forum > Software > Programming
Register FAQ Calendar Mark Forums Read

Programming The destination for developers - C, C++, Java, Python and the lot


Reply
 
LinkBack Thread Tools Display Modes
Old 08-10-2010, 02:10 AM   #1 (permalink)
Apprentice
 
veddotcom's Avatar
 
Join Date: Jan 2004
Location: Patna/Bhopal
Posts: 83
Default [C++] Need help with Pointers


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
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.
__________________
Think Before Implementing Your Thinking

Last edited by veddotcom; 08-10-2010 at 02:16 AM.
veddotcom is offline   Reply With Quote
Advertisements. Register and be a member of the community to get rid of them.
Advertisement

Old 08-10-2010, 10:33 AM   #2 (permalink)
XLr8
 
arpanmukherjee1's Avatar
 
Join Date: Sep 2008
Posts: 637
Default Re: Need Help With This C Code...

first error

second error:
first line of this page
__________________
Quote:
There are more things in heaven and earth, Horatio,
Than are dreamt of in your philosophy.
arpanmukherjee1 is offline   Reply With Quote
Old 10-10-2010, 12:24 AM   #3 (permalink)
Apprentice
 
veddotcom's Avatar
 
Join Date: Jan 2004
Location: Patna/Bhopal
Posts: 83
Default 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....
__________________
Think Before Implementing Your Thinking
veddotcom is offline   Reply With Quote
Old 11-10-2010, 09:26 AM   #4 (permalink)
XLr8
 
arpanmukherjee1's Avatar
 
Join Date: Sep 2008
Posts: 637
Default Re: Need Help With This C Code...

Quote:
Originally Posted by veddotcom View Post
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
__________________
Quote:
There are more things in heaven and earth, Horatio,
Than are dreamt of in your philosophy.
arpanmukherjee1 is offline   Reply With Quote
Old 11-10-2010, 02:13 PM   #5 (permalink)
Sami Hyypiä, LFC legend
 
Liverpool_fan's Avatar
 
Join Date: Jun 2007
Location: Нью-Дели
Posts: 2,138
Default 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.
__________________
Experience true education in Computer Science - http://www.udacity.com | http://www.coursera.org

Spoiler:
Read before asking / messaging any moderator for any query: FAQ + answers for new members

Read all the sticky threads before asking any type of query. Most basic questions are answered in those.
Don't use forum for chatting. Visit http://webchat.freenode.net/?channels=krow, enter nick and connect.
Liverpool_fan is offline   Reply With Quote
Old 13-10-2010, 01:30 PM   #6 (permalink)
Elevating Humanity
 
The Conqueror's Avatar
 
Join Date: Sep 2007
Location: Now on Earth
Posts: 1,954
Default Re: Need Help With This C Code...

Misleading Title. This is NOT a C Code. It is infact a C++ Code .
__________________
Regards,
The Conqueror
The Conqueror is offline   Reply With Quote
Reply

Bookmarks

Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On


 
Latest Threads
- by Charan
- by Charan
- by clmlbx

Advertisement




All times are GMT +5.5. The time now is 03:22 AM.


Powered by vBulletin® Version 3.8.7
Copyright ©2000 - 2012, vBulletin Solutions, Inc.

Search Engine Optimization by vBSEO 3.3.2