how to pass a nested structure pointer to function

P

prakashgkhaire

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 variable of 2nd structure to function as
variable of 1st structure

struct first
{
int val;
struct first *next;
};

struct second
{
int name;
struct first one;
struct second *next;
}temp2;

Now i found to pass actually first structure,
i.e let myfunc(temp) // void myfunc(struct first)
but can i do myfuc(temp2->one)
 
O

Old Wolf

struct first
{
int val;
struct first *next;
};

struct second
{
int name;
struct first one;
struct second *next;
}temp2;

Now i found to pass actually first structure,
i.e let myfunc(temp) // void myfunc(struct first)
but can i do myfuc(temp2->one)

You can do:

myfunc(temp2.one);
 
S

Sunil Varma

You can do myfunc(temp2.one)
but it's a good practice to send the address of a structure variable
and work on it than passing it by value.

Sunil
 

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,764
Messages
2,569,567
Members
45,041
Latest member
RomeoFarnh

Latest Threads

Top