What is the difference between Class and Structure?

Answers were Sorted based on User's Feedback



What is the difference between Class and Structure?..

Answer / eshetu

1. IN STRUCTURE THE DATA MEMBER BY DEFAULT IS PUBLIC BUT IN
CLASS THE DATA MEMBER ARE PRIVATE.
2. THE STRUCTURE ONLY CONTAIN DATA MEMBER BUT CLASS CONTAIN
DATA MEMBER & MEMBER FUNCTION.
3.IN STRUCTURE THE STRUCTURE NAME CAN'T STAND ALONE.BUT THE
CLASS NAME CAN STAND ALONE.

Is This Answer Correct ?    10 Yes 5 No

What is the difference between Class and Structure?..

Answer / liyakath ulla r

the structurs are used in both c and c++.
but class is used only in c++ and othe opps languages

Is This Answer Correct ?    67 Yes 63 No

What is the difference between Class and Structure?..

Answer / aashu gupta

There are only and only 2 differences between structure and class :
1. By default members are public in structures and private in class
2. Default inheritance in structure is public and private in class

you can verify the above differences by executing following code:
#include<iostream>

//code compiles and executes correctly means that //inheritance and polymorphism is allowed in structu
//res

using namespace std;

struct Base
{
int A;
virtual void display()=0; //polymorphism is allowed in structure
};

struct Derived:Base //public in struct and private in class
{
int B;
void display();
};

void Derived::display()
{
cout<<endl<<"A = "<<A<<endl;
}

int main()
{
Derived D;
D.A = 111;
D.display();
getchar();
return 0;
}

////////////////////////////////////////////////

Is This Answer Correct ?    5 Yes 1 No

What is the difference between Class and Structure?..

Answer / sudip das.

The difference between a CLASS and STRUCTURE are that:
1) CLASS are reference type where as STRUCTURE are value type.
2)By default,all of the members of a CLASS are private, but all of the members of a STRUCTURE are public.
3)CLASSES use heap but STRUCTURE use stuck.
4)CLASS members can be declared as protected but STRUCTURE members can not be.
5)CLASS contain data members and member function, but a STRUCTURE is contain only data member.

Is This Answer Correct ?    5 Yes 1 No

What is the difference between Class and Structure?..

Answer / vinod

The difference between a class and a structure is that, by
default, all of the members of a class are private and also private,public and protected but in structure by
default, all of the members of a structure are public.

Is This Answer Correct ?    5 Yes 3 No

What is the difference between Class and Structure?..

Answer / hardik savani

class is refrains type and structure is value type most op
us variable public and private in class.
public variable is use any component and private variable is use only class property

Is This Answer Correct ?    6 Yes 6 No

What is the difference between Class and Structure?..

Answer / pratiksha desarda

while creating variables of structure,it is compulsary to
write 'struct' keyword. and for creating object of class,
keyword 'class' is not necessary to write.

Is This Answer Correct ?    2 Yes 2 No

What is the difference between Class and Structure?..

Answer / guest

(1)Class Design For Object , Struct Design For Value Thus
Class is Refrence Type (Heape) but Struct is Value Type
(Stack) And Thus Struct is Faster Than Class ,

(2) Class is not Accessable Meanning We Can Access it By
Object , Struct is Accessable Meanning We Can Access it By
Value (Varible).

(3) Class Support Inheritance , Struct Not Support Inheritance .

(4)Class id Added Behavior (Methods) , Struct Not Added
Behavior

(5)Class Exist at higher Level of the Program , Struct Exist
at Lowest Level of the Program .

(6) A struct cannot declare a default constructor (a
constructor without parameters) or a destructor.Class Can .

(7)a small class may be more efficiently handled by the
system if you declare it as a struct instead.

Is This Answer Correct ?    2 Yes 2 No

What is the difference between Class and Structure?..

Answer / ramesh.alavala

class provides data hiding,structures doesn't provide.
class support polymorphism,structures doesn't support.
classes by default are inherited by privately,structures are
inherited by publicly.
classes can be abstract, structures can't be abstract.

Is This Answer Correct ?    3 Yes 3 No

What is the difference between Class and Structure?..

Answer / rohit patil

Syntax of class
class class_name
{
variable_declaration
function_declaration
};

syntax of structure
struct struc_name
{
variable declaration
};

Is This Answer Correct ?    2 Yes 2 No

Post New Answer

More C++ General Interview Questions

what is the order of initialization for data?

10 Answers   Amazon, TCS, Wipro,


1.Between 100 and 999 are some numbers that have the characteristics that if you cube the individual digits and sum together you will get the same number. 2. A program that can accept as input an integer and output the equivalent of that number in words.

3 Answers  


What are Virtual Functions? How to implement virtual functions in "C" ?

3 Answers  


Types of storage and scope of each type

2 Answers   CA,


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

0 Answers  






structure that describe a hotel with name, address,rooms and number of rooms

2 Answers  


Which is not a valid keyword a) public b) protected c) guarded

0 Answers  


Why do we need function?

0 Answers  


What is a responder chain?

0 Answers  


Why for local variables the memory required to hold the variable is allocated from the program stack and for new its allocated from the heap?

1 Answers  


What is static function? Explain with an example

0 Answers  


What are the advantages of inheritance in c++?

0 Answers  


Categories