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

What is a driver program?

643


When should we use multiple inheritance?

626


What is dynamic and static typing?

685


How can we check whether the contents of two structure variables are same or not?

598


Is it possible to write a c++ template to check for a function's existence?

586






What are the advantages of using a pointer? Define the operators that can be used with a pointer.

616


How many types of scopes are there in c++?

589


How do you compile the source code with your compiler?

628


What is token c++?

592


What is c++ prototype?

597


Which software is used to run c++ program?

561


What is abstraction c++?

599


Why is swift so fast?

632


What is pair in c++?

639


What is the difference between an external iterator and an internal iterator? Describe an advantage of the external iterator.

570