473,385 Members | 2,180 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,385 software developers and data experts.

Is it the same?

QQ
For instance I have a struct

struct A{
char ID[10];
}A;

when I call the ID in struct A

A aa;
is &aa.ID[0] and aa.ID
the same?

Thanks a lot!

Nov 15 '05 #1
3 1431
"QQ" <ju****@yahoo.com> wrote:
For instance I have a struct

struct A{
char ID[10];
}A;

when I call the ID in struct A
You do not call an array. You call a function.
A aa;
is &aa.ID[0] and aa.ID
the same?


Depends on the context. Usually, yes, they are the same (or more
precisely, aa.ID is evaluated as if it were the same as &aa.ID[0]).
But for example, as the operand of sizeof, they're not the same: sizeof
&aa.ID[0] is equal to sizeof (char *), while sizeof aa.ID is equal to
10*sizeof char, i.e., to 10.

Richard
Nov 15 '05 #2
QQ wrote:
For instance I have a struct

struct A{
char ID[10];
}A;

when I call the ID in struct A

A aa;
is &aa.ID[0] and aa.ID
the same?


Formally speaking, no. One example where thse two behave differently was already
mentioned by Richard.

Also one can note that the former is an lvalue, while the latter is an rvalue.
There are contexts where this will make a difference. For example, you can apply
an 'address-of' operator to 'aa.ID' and get the pointer to the entire array
(pointer of type 'char (*)[10]')

char (*ptr)[10 = &aa.ID;

However, it is worth mentioning that in virtually all other contexts these two
variants will behave identically.

--
Best regards,
Andrey Tarasevich
Nov 15 '05 #3
Andrey Tarasevich wrote:
QQ wrote:
For instance I have a struct

struct A{
char ID[10];
}A;

when I call the ID in struct A

A aa;
is &aa.ID[0] and aa.ID
the same?


Formally speaking, no. One example where thse two behave differently was
already mentioned by Richard.

Also one can note that the former is an lvalue, while the latter is an
rvalue.


Sorry, should be other way around.

--
Best regards,
Andrey Tarasevich
Nov 15 '05 #4

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

44
by: bq | last post by:
In the code int a; int b = -1; does ANSI C guarantee that "b" is located in memory right after "a" so that "a" refers to "b"? Thanks. bq
2
by: Daniel Goldman | last post by:
Hi, Any advice about both a BinaryReader and BinaryWriter containing same FileStream at same time? Like: Stream fs = new FileStream("output.dbf", FileMode.Create); BinaryReader br = new...
4
by: don | last post by:
I have two existing interfaces having methods with same names. Now I have to implement both intrfaces in one class. Is there any way I could implement methods with same names in both interfaces...
7
by: Sharon | last post by:
Hi all, I've implemented a TCP server using the Socket async methods. When connecting to the server from 3 instances of hyper terminal, i've noticed that each of the newly created server sockets,...
6
by: Joseph Geretz | last post by:
Writing an Outlook AddIn with C#. For the user interface within Outlook I'm adding matching pairs of Toolbar buttons and Menu items. All of the buttons and menu items are wired up to send events to...
20
by: subramanian | last post by:
Hello I have a doubt in the following piece of code: int a; printf("a=%p\n", a); printf("&a=%p\n", &a); these printf statements print the same value for both 'a' and '&a". I tried in...
8
by: jaibux | last post by:
Everybody knows how to open (or clone) the same page that you are viewing in a new browser window by CTRL+N or via File->New Window. the question is how to PREVENT to open the SAME WEB APPLICATION...
16
by: Zytan | last post by:
MSDN says: "The ref and out keywords are treated differently at run- time, but they are treated the same at compile time. Therefore methods cannot be overloaded if one method takes a ref argument...
28
by: SzH | last post by:
Suppose that there is a program that takes two files as its command line arguments. Is there a (cross platform) way to decide whether the two files are the same? Simple string comparison is not...
7
by: Yen Kwoon | last post by:
Note: This problem is related to gcc but after some back and forth in group gnu.gcc.help it seems to have morph into more of a c++ specificiation question, hence the transplanting to this group. ...
1
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome former...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.