473,322 Members | 1,846 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,322 software developers and data experts.

Structure Variable

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?
Nov 14 '05 #1
4 1167
rsk


Rex wrote:

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);
Nov 14 '05 #2
rsk wrote:

Rex wrote:
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);


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

Mark

--
<<Remove the del for email>>
Nov 14 '05 #3
rsk


Capstar wrote:

rsk wrote:

Rex wrote:
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);


yes here to print the address of s1.j . am i right mark ?if no correct me.
shouldn't that be
printf("%d%d",*s2->i,s2->j);


yes for to print the value s1.j
Nov 14 '05 #4
rsk wrote:
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);

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

--
<<Remove the del for email>>
Nov 14 '05 #5

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

Similar topics

4
by: D Witherspoon | last post by:
I have a Structure I have created and am using it as a Public Property of a class. Here is the property. ------------------------------------------------------ Dim _MyID As SInteger Public...
3
by: zhphust | last post by:
I want to convert a object of a managed class to a unmanaged structure that has the same member with that managed class. Can anybody tell me how i can do it? Thanks in advance. -- zhphust...
8
by: Charles Law | last post by:
Can anyone suggest how I would marshal a variable length structure back from an API call. Specifically, I am looking at the WaitForDebugEvent function, which returns a DEBUG_EVENT structure. ...
2
by: Dennis | last post by:
Does anyone know why this code gives an error: <serializeable> public structure TestSerialize anumber as integer astring as string end strucuture Dim t As TestSerialize Dim formatter As New...
15
by: Charles Law | last post by:
I have adapted the following code from the MSDN help for PropertyInfo SetValue. In the original code, the structure MyStructure is defined as a class MyProperty, and it works as expected. There is...
2
by: prakashgkhaire | last post by:
i have two structure where first structure consists val and structure pointer(linklist), 2nd structure consists, val, a varialbe of first structure, pointer of structure. Now i found to pass the...
1
by: Falko Wagner | last post by:
Hi there, I am currently translating a VB 6.0 application to .NET and have the following problem: The data structure I need to pass to a DLL function call has a structure variable inside its...
12
by: Sam Kong | last post by:
Hi, JavaScript hides its memory structure. I know that numbers, booleans, null and undefined are value types (value is directed saved in a variable). I want to know: - How JavaScript...
0
by: MikeCS | last post by:
Hi all I would like some help with this issue. I am new to VB 2005 (OK with VB6) My problem is that I cannot seem to return a structure from a function. Example: I defined a structure in a...
0
by: RobbieJosefson | last post by:
I want to marshal a structure containing a variable length array which will be populated within a C++ dll. the structure is the following Public Structure myStructure{ Public int size;...
0
by: DolphinDB | last post by:
Tired of spending countless mintues downsampling your data? Look no further! In this article, you’ll learn how to efficiently downsample 6.48 billion high-frequency records to 61 million...
0
by: ryjfgjl | last post by:
ExcelToDatabase: batch import excel into database automatically...
0
by: jfyes | last post by:
As a hardware engineer, after seeing that CEIWEI recently released a new tool for Modbus RTU Over TCP/UDP filtering and monitoring, I actively went to its official website to take a look. It turned...
0
by: ArrayDB | last post by:
The error message I've encountered is; ERROR:root:Error generating model response: exception: access violation writing 0x0000000000005140, which seems to be indicative of an access violation...
1
by: PapaRatzi | last post by:
Hello, I am teaching myself MS Access forms design and Visual Basic. I've created a table to capture a list of Top 30 singles and forms to capture new entries. The final step is a form (unbound)...
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...
1
by: Defcon1945 | last post by:
I'm trying to learn Python using Pycharm but import shutil doesn't work
1
by: Shællîpôpï 09 | last post by:
If u are using a keypad phone, how do u turn on JavaScript, to access features like WhatsApp, Facebook, Instagram....
0
by: af34tf | last post by:
Hi Guys, I have a domain whose name is BytesLimited.com, and I want to sell it. Does anyone know about platforms that allow me to list my domain in auction for free. Thank you

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.