What is the difference between Class and Structure?
Answers were Sorted based on User's Feedback
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 |
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 |
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 |
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 |
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 |
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 |
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 |
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 |
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 |
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 |
Write about all the implicit member functions of a class?
What is c++ map?
what is VOID?
What are the differences between a struct and a class in C++?
What is a smart pointer?
What are special characters c++?
What is std :: flush?
Is c++ fully object oriented?
What is the history of c++?
Should I learn c++ c?
Are strings mutable in c++?
How a new operator differs from the operator new?