[Solved] What kind of code is this? C or C++ [closed]


Your code is, as far as I can tell, valid C++. It is not valid C, but could be made valid C with only a little effort.

C is nearly a subset of C++, but there is valid C code that is not valid C++ code — and of course there’s plenty of valid C++ code that’s not valid C code.

The one thing that makes your code invalid as C is the use of the name node:

typedef struct node
{
    int data;
    node *next;
}node;

In C++, the struct node definition makes the type visible either as struct node or as node. In C, the struct definition by itself only creates the name struct node. The name node is not visible until the typedef is complete — which it isn’t at the point where you define node *next;.

If you rename your source file with a .c suffix and compile it as C, the compiler will complain that node is an unknown type name.

1

solved What kind of code is this? C or C++ [closed]