Creating struct variable using the tag name

c, c++, declaration, struct

Solution

It is the difference between C++ and C. The author you are citing speaks about C while you use C++ code instead of C code. In C you have to specify keyword struct, union or enum before declaring variables of correspondings types.

Problem

I have read a article in the following link http://www.embedded.com/electronics-blogs/programming-pointers/4024450/Tag-vs-Type-Names Here author says that, use of follwing is wrong. ``` struct s { -- }; s var; ``` But in my sample code its works perfectly. ``` 1 #include<iostream> 2 using namespace std; 3 4 struct s 5 { 6 int sd; 7 }; 8 s v; 9 10 11 12 int main() 13 { 14 15 v.sd=10; 16 cout<<v.sd; 17 return 0; 18 } ``` EDIT: What the actual difference? why it works in c++ and not works in c;

Original source

Related problems