Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

C structure and C++ structure

Tags:

c++

c

Could anybody please tell me what is the main difference between C & C++ structures.

like image 724
Vijay Avatar asked Feb 11 '10 06:02

Vijay


People also ask

What is C Explain structure of C with example?

Example of C Structures }; struct bill { float amount; int id; char address[100]; }; struct bill { float amount; int id; char address[100]; }; In the above example, we have defined a structure named bill. And the members of this structure are amount, id and address.

What Is syntax of structure in C?

Syntax of structstruct structureName { dataType member1; dataType member2; ... }; For example, struct Person { char name[50]; int citNo; float salary; }; Here, a derived type struct Person is defined. Now, you can create variables of this type.

What are the used of C structures?

Arrays allow to define type of variables that can hold several data items of the same kind. Similarly structure is another user defined data type available in C that allows to combine data items of different kinds.

What is structure C program?

Most programming languages have a structure, including the C language. A 'C' program is divided into six sections: Documentation, Link, Definition, Global Declaration, Main() Function, Subprograms. While the main section is compulsory, the rest are optional in the structure of the C program.


1 Answers

In C++ struct and class are the exact same thing, except for that struct defaults to public visibility and class defaults to private visiblity.

In C, struct names are in their own namespace, so if you have struct Foo {};, you need to write struct Foo foo; to create a variable of that type, while in C++ you can write just Foo foo;, albeit the C style is also permitted. C programmers usually use typedef struct {} Foo; to allow the C++ syntax for variable definitions.

The C programming language also does not support visibility restrictions, member functions or inheritance.

like image 177
Tronic Avatar answered Sep 21 '22 15:09

Tronic