Difference between Class and Struct.

Answer Posted / 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



Post New Answer       View All Answers


Please Help Members By Posting Answers For Below Questions

What is a function simple definition?

618


what is the difference between 123 and 0123 in c?

722


What is main return c?

519


What is mean by data types in c?

551


How can I read in an object file and jump to locations in it?

579






Describe dynamic data structure in c programming language?

604


What is restrict keyword in c?

645


Add Two Numbers Without Using the Addition Operator

353


Are there namespaces in c?

568


What is the difference between ā€˜gā€™ and ā€œgā€ in C?

2540


Explain the advantages of using macro in c language?

582


how to capitalise first letter of each word in a given string?

1434


What is main function in c?

551


How pointers are declared?

560


A set of N billiard balls are set on a one-dimensional table. The table is 1 meter long, set north-south with two pockets at either side. Each ball has zero width and there is no friction so it is moving with a fixed velocity of either northward or southward and bounces back in a perfect elastic collision from other balls it encounter on its way (or drop into one of the pockets). Your job is to keep track of the balls movements. Task Please write a program that gets the initial place, speed and direction of all the balls and gives the position of a specific ball after t seconds. Input The first line contains the number of scenarios. Each one of the other lines in the input contains a scenario: The first number, N, is the number of balls; followed by N pairs of numbers: the distance in centimeters from the south end of the table and the speed (positive speed meaning it moves northward); the last two numbers are the number i of the target ball you should track and the time T in seconds. Output The output is a single number for each line which is the place (distance in centimeters from the south end of the table) of the tracked ball after T seconds. Note: There is no new line character at the end of the result. Sample Input 5 1 50 1 1 1000 1 50 1 1 6 1 60 -2 1 6 2 10 1 95 -1 2 30 2 10 1 95 -1 2 60 Sample Output 100 56 48 65 70

2134