• 0

typedef struct vs. struct


Question

1 answer to this question

Recommended Posts

  • 0

Struct's are defined as: struct name {...}; Using typedef on a struct is no different than using typedef on an int.

I: typedef a "nameless struct" to s1. I don't believe this is standard C++ (should work on VC++ though). You would refer to the struct as follows:

s1 s;

s.n1 = 2;

II: named struct s2. Using this version is basically the same as above:

s2 s;

s.n1 = 2;

In C, you need to do "struct s2 s;" though.

III: I don't believe this will compile.

This topic is now closed to further replies.
  • Recently Browsing   0 members

    • No registered users viewing this page.