user1669228
user1669228

Reputation: 1

Declaring new instance of structure in C

struct xampl {
       int x;
       char y;
};

struct xampl InstaceOfxampl;
struct xampl *PointerToxampl;
struct xampl &new_struct;

We are creating a simple instance in first case, and a pointer to structure xampl in second. However what does the third declaration mean? How is it handled differently as compared to other two in code?

Upvotes: 0

Views: 2824

Answers (2)

Vijay
Vijay

Reputation: 67319

you can access a member of the structure:

  • first one(structure variable) using a .
  • second one(structure pointer) using a ->

you can store the address of the first one in the second one like:

PointerToxampl=&InstaceOfxampl;

as everybody else said third one is invalid thing to do.if you want to decalre a reference.it should be done as below:

struct xampl &new_struct=InstaceOfxampl;

Upvotes: 0

md5
md5

Reputation: 23727

In C++, struct xampl &new_struct declares a reference (however, it is invalid, because a reference have to be initialized). In C, it does not mean anything, here.

Upvotes: 5

Related Questions