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 |
What is the real purpose of class – to export data?
How would you call C functions from C++ and vice versa?
Write a program to show polymorphism in C++?
Can java be faster than c++?
What are the differences between malloc() and calloc()?
How do I use turbo c++?
How is computer programming useful in real life?
What is the type of this pointer in c++?
What is lambda expression c++?
Where and why do I have to put the "template" and "typename" keywords?
Any one help me plzzzz..... i have an assignment...... that is ______*********_______ Write a program that takes an equation as a string and does the following: Solve 8 parts to achieve 100% 1 - 5 are compulsory. Input: 2x^2+3x+4=0 1) read a quadratic equation 2) print its coefficients (coefficients range is 0 to 9) 3) print the solution of the equation 4) tackle imaginary solution e.g. ( (2+3i), (2-3i) ) 5) allow spaces within the input 6) after solving one equation; ask for an other, terminate on empty line. * 7) tackle negative values as well * 8) tackle more than one values of same exponent (e.g. 2x^2 + 3x^2 + 4x + 3 = 0)* 9) use strtok * 10) print the solution in fractions e.g. 1.5 should be printed as (1)1/2 * 11) coefficient can be greater than 9** 12) values on both sides of the ‘=’ sign** 13) plot the graph of the polynomial** 14) use a compiler other than Borland** 15) submit before May 25, 2009 11:59 PM ** _______******________ plz send me c++ code at sweety.alvi@gmail.com
What is the difference between the functions memmove() and memcpy()?