What is the difference between Class and Structure?

Answer Posted / uppu goutami

In C++, A structure can have both variable and functions as members.It can also declare some of its members as 'private' so that they cannot be accessed directly by the external functions.
In C++, The structure names are stand-alone and can be used like any other type names. That is, the keyword 'struct' can be omitted in the declaration of structure variable.
For example, We can declare the student variable.
For student A; // c++ declaration
This is an error in C.
C++ incorporates all these extensions in another user-defined type known as 'class'. There is very little syntactical difference between class and structure in C++ and, therefore, They can be used interchangeably with minor modifications. Since 'class' is a specially introduced data type, most of the C++ programmers tend to use the structures for holding only data, and classes to hold both the data and functions.

Is This Answer Correct ?    0 Yes 0 No



Post New Answer       View All Answers


Please Help Members By Posting Answers For Below Questions

Why is c++ still popular?

589


What are the extraction and insertion operators in c++?

565


Show the declaration for a static member variable.

534


What is c++ flowchart?

681


Incase of a function declaration, what is extern means?

521






How can you link a c++ program to c functions?

624


What is class syntax c++?

595


Why do we learn c++?

531


Which command properly allocates memory a) char *a=new char[20]; b) char a=new char[20]; c) char a=new char(20.0);

620


What are the uses of c++ in the real world?

566


How would you use the functions randomize() and random()?

629


what is Member Functions in Classes?

620


What are literals in C++?

601


why is iostream::eof inside a loop condition considered wrong?

595


What is a container class?

623