CoolInterview.com - World's Largest Collection of Interview Questions
Send Free SMS
 Interview Questions  
 Our Services  


INTERVIEW QUESTIONS LANGUAGES C++ DETAILS
Question :
What is the difference between class and structure?
Category C++ Interview Questions
Rating (4.2) By 45 users
Added on 10/22/2004
Views 8537
Rate it!
Answers:

Structure: Initially (in C) a structure was used to bundle different type of data types together to
perform a particular functionality. But C++ extended the structure to contain functions also. The
major difference is that all declarations inside a structure are by default public.

Class: Class is a successor of Structure. By default all the members inside the class are private.



one more difference apart from public and private access specifier, that struct dont have protected as an access specifier while class do.



 Posted by: Napster    

Contact Napster  Contact Napster

There are two differences between Structure and Class. Firstly, Structure cannot be inherited. Secondly, Structure is a value data type whereas Class is a reference type.



 Posted by: Hao Quang    

Contact Hao Quang  Contact Hao Quang

1) structure instances cannot be used as operand to arithmetic operators like +-*/ . But object (instances of classes) can be (using operator overloading).
2) There is no data hiding features comes with structures. Classes do, private, protected and public



 Posted by: somnath pal    

Contact somnath pal  Contact somnath pal

A structure is a convenient tool for handling a logicaly related data items,it is a user defined data type with templet.
Example:
struct student
{
char name[20];
int Roll_no;
float marks;
};
A class is an extention of the idea of stucture used in C.It is a way of creating and implementing a user defined data type
Example:
class class_name
{
private:
variable declaration;
function decleration;
public:
variable declaration;
function decleration;
};
A structure do not hav the property of data hiding that is all the members of structure are accessible by any function anywere in there scope.that is the data member of structure are public by default
A class have the property of data hiding that is the data member of the class are accessible only by there object,the data member of class are private by default



 Posted by: kanika khanna    

Contact kanika khanna  Contact kanika khanna

the difference between class and structure are by default all the data members are private but in structure by default it's private.



 Posted by: Basavant    

Contact Basavant  Contact Basavant

class:-
class is extracted for the fetures of oops
sturcture
structure the collection of all members of different data types
class:-
in class we can use all the 3 access specifiers and they are
1.private
2.public
3.protected
structure:-
we use only private(defult)
structure:-
structure has a keyword struct
class:-
class itself is an keyword
sturcture:-
structure has more security
class:-
class has a low security when compared to structure
structure:
we use "->" for accessing
class:-
in class we use "."



 Posted by: P.ASHWINI    

Contact P.ASHWINI  Contact P.ASHWINI

1.By default the members of a structure are public and for a class they are private.
2.A structure can't declare protected members,a class can.
3.A structure can't be abstract, a class can.
4.A structure is a value type, while a class is a reference type.



 Posted by: Monalisha Nayak    

Contact Monalisha Nayak  Contact Monalisha Nayak

Structure:
1. By default, the members of a structure are public i.e structure variables can be accessed by any function (data hiding is not possible)

2. In structure, we can declare only variables.

3. we can't inherit a structue from another structure.

class:
1. By default, the members are private i.e class variables can be accessed by only class member functions. (datahiding is possible)

2. In classes we can declare both data members and member functions.

3. We can inherit a class from another class.



 Posted by: AnuradhaSrikanth    

Contact AnuradhaSrikanth  Contact AnuradhaSrikanth


If you have the better answer, then send it to us. We will display your answer after the approval.
Name :*
Email Id :*
Answer :*
Verification Code Code Image - Please contact webmaster if you have problems seeing this image code Not readable? Load New Code
Process Verification  Enter the above shown code:*
Inform me about updated answers to this question

   
Related Questions
View Answer
What is friend function?
View Answer
What are virtual functions?
View Answer
What is a scope resolution operator?
View Answer
What do you mean by inheritance?
View Answer
What is polymorphism? Explain with an example?
View Answer
What is the difference between an object and a class?
View Answer
What is encapsulation?
View Answer
What is abstraction?
View Answer
What do you mean by binding of data and functions?
View Answer
Difference between realloc() and free()?
View Answer

Please Note: We keep on updating better answers to this site. Subscribe to our newsletter to get notified when better answer is posted.

Notify me when better answer is posted!
Email:

View ALL C++ Interview Questions

User Options
Sponsored Links


Copyright ©2003-2010 CoolInterview.com, All Rights Reserved.
Privacy Policy | Terms and Conditions
Page URL: http://www.coolinterview.com/interview/956/default.asp?cachecommand=bypass


Download Yahoo Messenger | Placement Papers| FREE SMS | ASP .Net Tutorial | Web Hosting | Free SMS | Dedicated Servers | Joke of the Day

0.64