Difference between Class and Struct.

Answers were Sorted based on User's Feedback



Difference between Class and Struct. ..

Answer / swetcha

The only difference between a struct and a class is in the
default access. By default, all the members of a struct are
public whereas in a class, al the members are private. The
same is true for the default inheritance type: a struct
entails public inheritance by default whereas a class
entails private inheritance.

Is This Answer Correct ?    98 Yes 23 No

Difference between Class and Struct. ..

Answer / praveena.g

class ex:-
class classname
{
int a;
float b;
}
struct {
int a;
int b;
}struct name;

in the struct all members are by default public,
in the class we can deference it private,public,protected.
like these we class will taken.

Is This Answer Correct ?    62 Yes 19 No

Difference between Class and Struct. ..

Answer / ajay prajapat

1. Structure is value type where is class is refrance
type.So class data is store in heap where as stuct data are
store in stack.

2. default type of function in struct is public where as
private in class

Is This Answer Correct ?    55 Yes 15 No

Difference between Class and Struct. ..

Answer / kishore

What is the difference between class and structure?

1) 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.

2) structures in c++ doesn't provide data hiding where as a
class provides data hiding

classes support polymorphism, whereas structures don't
3) class and structure are very similar. the former is
heavyweight while the latter is light weight. reference to
the former rests on the heap..while the latter in whole
(instance and data) rests on the stack. therefor care
should be taken not to make a struct very heavy else it
overloads the stack causing memory hogging. class needs to
have an instance explicitly created to be used. A struct
doesn't have to be explicitly initiated

Is This Answer Correct ?    44 Yes 7 No

Difference between Class and Struct. ..

Answer / jammu hari (v.v. narasimharao

Difference between class & Structure is :-
-------------------------------------------

1. class = data + functions
structure=Collection of different data
2. Class supports Re-usability. Structures are used to handle
the complex data.
3. Both are user defined data types.
4. 'struct' is a keyword which is used to declare a structure.
'class' is a keyword used to declare a class.
5. By default all the structure members are public. But in
class all the members are private.
6. Structure variable is used to access the structure
members. Object is used to access the class members.
7. Structure is less secure than the class.
8. Structure is a procedure Oriented feature. Object is a
Object Oriented Feature.
9. Both Structure & Class uses (.) dot operator to access
their members.
10. class contains 3 access specifiers But structure has
only 1 access specifier.
11. We can inherit a class. But we can't inherit structure.
12. We can declare constructors & destructors inside of a
class. But we can't declare these in Structure.
13. Structure are not suitable of Data Hiding. But classes
well suited for data hiding.
14. Structure is a valute type. Class is a reference type.
so, class data is stored in heap & structure data is
stored in stack.
15. class is an extension to the structure.
16. structures are used to handle the complex data.
class is used for reusability.

Is This Answer Correct ?    41 Yes 14 No

Difference between Class and Struct. ..

Answer / jammu hari cell:9848278041

Difference between class & Structure is :-
-------------------------------------------

1. class = data + functions
structure=Collection of different data
2. Class supports Re-usability. Structures are used to handle
the complex data.
3. Both are user defined data types.
4. 'struct' is a keyword which is used to declare a structure.
'class' is a keyword used to declare a class.
5. By default all the structure members are public. But in
class all the members are private.
6. Structure variable is used to access the structure
members. Object is used to access the class members.
7. Structure is less secure than the class.
8. Structure is a procedure Oriented feature. Object is a
Object Oriented Feature.
9. Both Structure & Class uses (.) dot operator to access
their members.
10. class contains 3 access specifiers But structure has
only 1 access specifier.
11. We can inherit a class. But we can't inherit structure.
12. We can declare constructors & destructors inside of a
class. But we can't declare these in Structure.

Is This Answer Correct ?    20 Yes 8 No

Difference between Class and Struct. ..

Answer / rahul yadav

wrong
structs can also contain functions in C++,
but in C, i ma not sure.
but since we are talking abot Class so we have to answer in
the context of C++,hence the answer is wrong.
only diff is of default variable scope.

Is This Answer Correct ?    37 Yes 27 No

Difference between Class and Struct. ..

Answer / naresh kukreti

The struct default access type is public. A struct should
typically be used for grouping data.

The class default access type is private, and the default
mode for inheritance is private. A class should be used for
grouping data and methods that operate on that data.

In short, the convention is to use struct when the purpose
is to group data, and use classes when we require data
abstraction and, perhaps inheritance.

In C++ structures and classes are passed by value, unless
explicitly de-referenced. In other languages classes and
structures may have distinct semantics - ie. objects
(instances of classes) may be passed by reference and
structures may be passed by value.

Is This Answer Correct ?    5 Yes 0 No

Difference between Class and Struct. ..

Answer / naresh kukreti

1)measure difference between structure and class is that
the structure doesn't inherit but class is inherit
2)by default the data members of structure are public but in
case of class data members are private
3) Class is much secure ,but structure is not secure

Is This Answer Correct ?    4 Yes 0 No

Difference between Class and Struct. ..

Answer / frozan maqsoodi

the main difference is the default access specifier.
constructors can be declared in structures. try it, you
will get the answer.

Is This Answer Correct ?    1 Yes 0 No

Post New Answer

More C Interview Questions

Place the #include statement must be written in the program?

0 Answers  


exit () is used to a) exit () terminates the execution of the program itself b) exit () terminates the execution of the loop c) exit () terminates the execution of the block d) none of the above

0 Answers  


Why is main function so important?

0 Answers  


What is the difference between printf and scanf )?

0 Answers  


Ca some one please help me with aC code to allow user enter numbers from 1 to 20 without repeating and prnt the sum of those numbers thnx

4 Answers  






What is struct node in c?

0 Answers  


What are pointers really good for, anyway?

0 Answers  


Write a pro-gramme to determine whether the number is even or odd?

1 Answers  


What 'lex' does?

0 Answers   Tech Mahindra,


increment operateor (++)and decrament(--) #include<stdio.h> #inclide<conio.h> main() { int x=15; while(x!=0) scanf("%d",&x); {

2 Answers   HCL, Syntel, TCS,


Write a program to reverse a given number in c?

0 Answers  


3. Program to print all possible substrings. ex: String S St Str Stri Strin String t tr tri trin tring r

3 Answers   Huawei,


Categories