Thursday, May 3, 2007

C Structure vs C++ Structure

C Structure contains only data items while C++ structure contains data as well as function.

In C to create structure variable you have to use 'struct' keyword for example
struct Person p;

But in C++ 0nly Structure name is used just like built-in datatype. for example
Person p;

Example :

C Structure :
struct Person
{
int pid;
char name[25];
....
}
Declaration of a variable
struct Person p;

C++ Structure :

struct Person
{
int pid;
char name[25];
....
void enterDetails()
{
...
}
..
}

Declaration of a variable:
Person p;