sattu
sattu

Reputation: 650

returning struct* from a function

I have following code

struct myStruct *struct_var;
struct myStruct * select_my_struct()
{
return struct_var;
}
some_function()
{
    myStruct=struct_create();//struct_create() is of return type struct myStruct *
    another_function(struct_var);   // line A
    another_function(select_my_struct()); //line B
}

My question is: do the line A and line B does the same thing?

Upvotes: 1

Views: 166

Answers (2)

ant2009
ant2009

Reputation: 22486

Yes, it has the same declaration, as it takes a pointer to a mystruct datatype.

Upvotes: 1

masoud
masoud

Reputation: 56479

struct_var is a pointer and select_my_struct() returns where struct_var points to.

So both of them are same.

Upvotes: 2

Related Questions