Structure Variable

R

Rex

hai all,
its a small doubt,

struct temp
{
int *i;
int j;
}s1,*s2;

now how do i use this structure variables(both s1 & s2) to
access the variables *i & j.and plz explain how?
 
R

rsk

Rex said:
hai all,
its a small doubt,

struct temp
{
int *i;
int j;
}s1,*s2;

now how do i use this structure variables(both s1 & s2) to

you can use it by this way
s2 =&s1;
access the variables *i & j.and plz explain how?
for access i and j

for example
s1.j=5;
s1.i= &(s1.j);
printf("%d%d",s2->i,s2->j);
 
C

Capstar

rsk said:
you can use it by this way
s2 =&s1;



for access i and j

for example
s1.j=5;
s1.i= &(s1.j);
printf("%d%d",s2->i,s2->j);

shouldn't that be
printf("%d%d",*s2->i,s2->j);

Mark
 
C

Capstar

rsk said:
yes here to print the address of s1.j . am i right mark ?if no correct me.

I think on most systems, this will give you the address of s1.j in
decimal notation. But I'm not sure what will happen if sizeof(int) and
sizeof(int*) are not the same on a particular system.

I do believe the right way to do this would be:
printf("%p%d",(void*)s2->i,s2->j);

But I'm no expert in this field, so please correct me again if I'm wrong.

Mark
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,769
Messages
2,569,580
Members
45,054
Latest member
TrimKetoBoost

Latest Threads

Top