What are the differences between a struct and a class in
C++?

Answers were Sorted based on User's Feedback



What are the differences between a struct and a class in C++?..

Answer / rsn

Hello Shivani,

I think both struct and class in C++ are quite the same
except for the fact that, members in struct are public by
default whereas they are private for class.
Moreover struct also supports inheritance,polymorphism
etc...etc...

Is This Answer Correct ?    14 Yes 0 No

What are the differences between a struct and a class in C++?..

Answer / amit patel

Rsn answer is perfect write.Shivani you are wrong.
the visiblity of members default public in structure,
whereas in class its private as all know.
So please don't make myths here.

for the detail answer for explanation read the following link.

http://carcino.gen.nz/tech/cpp/struct_vs_class.php

Is This Answer Correct ?    5 Yes 2 No

What are the differences between a struct and a class in C++?..

Answer / ramesh kasi

The only difference is related to the default access
specifier.
The members of a structure have public access by default.
The members of a calss have private access by default.

Is This Answer Correct ?    3 Yes 1 No

What are the differences between a struct and a class in C++?..

Answer / supriya

Memory is alloated on Stack using Structure whereas in class its heap , that is it wont be stored at an contagious memory location.

Is This Answer Correct ?    0 Yes 0 No

What are the differences between a struct and a class in C++?..

Answer / ajit

In structures by default the member variables considered as
public where as in classes by default data members are
considered as private.
Structures doesn't provide the concept data encapsulation
but classes provides it.

Is This Answer Correct ?    0 Yes 1 No

What are the differences between a struct and a class in C++?..

Answer / shivani

In Class Members are private by default.
In Structure Member are public by default.
structures are value typed where as classes are refernce
typed

Class can be inherited But Structure can't be inherited

In structures we cannot initilase the variable during the
declaration while in classes we can.

Structure s does not support polymorphism while class does

Structure can be declared without a tag at the first time,
but not in case of class.

e.g. struct { variables; }(struct variable list); [It would
not raise any error while comlitation]

class { access specifier: variable list; access specifier:
vari....

}; [it will cause an error while compilation]

Is This Answer Correct ?    3 Yes 6 No

What are the differences between a struct and a class in C++?..

Answer / rajesh

shivani is wrong bec. structure is not inherited.

Is This Answer Correct ?    0 Yes 6 No

Post New Answer

More C++ General Interview Questions

write a program in c++ to implement stack using functions in header file stack.h

3 Answers   Google, Subex,


What is endl?

0 Answers  


write a program that reads in a file and counts the number of lines, words, and characters. Your program should ask the user to input a filename. Open the file and report an error if the file does not exist or cannot be opened for some other reason. Then read in the contents of the file and count the number of lines, words, and characters in the file. Also print additional information about the file, such as the longest and shortest words, and longest and shortest lines. For simplicity, we define a word to be one or more characters ending with white space (a space, tab, carriage return, etc.). Functions for checking the types of characters can be found in the ctype.h header file, so you want to include this header file in your program. For example, the sentence below could be all that is in a file. This sentence IT 104 is taught in C++. has 32 characters, one line, and six words. The shortest line is 32 characters. The longest line is 32 characters. The shortest word is 2 characters. The longest word is 6 characters

0 Answers  


What is overloading unary operator?

0 Answers  


What is the best book for c++ beginners?

0 Answers  






Explain 'this' pointer and what would happen if a pointer is deleted twice?

0 Answers   Genpact,


what is the size of a class which contains no member variables but has two objects??? is it 1 or 2??

4 Answers  


What is prototype for that c string function?

0 Answers  


What is c++ hash?

0 Answers  


sizeof - is it a function or operator?

6 Answers   Honeywell,


What is an undefined reference/unresolved external symbol error and how do I fix it?

0 Answers  


Difference between linked list and array?

3 Answers  


Categories