Memory allocation for objects, C/C++ Programming

when a class is defined the compiler will not allocate memory.

This is true only for data member not for member function.  As soon as the member function is defined  the required  memory  for that  member  function  is allocated. The  memory  for data member (variable) is allocated only when the object is constructed from the class.

class item

{ int number; float cost; public:

void getdata(int a, float b);

void putdata(void);

};

In the class item the memory is allocated  for getdata and putdata member functions.

Memory is not allocated for number and cost data members.

 

item p;  Now the memory is allocated for data member number and cost. The memory is allocated for each instances of object.

item p,q,r,s;  The memory is allocated for data members of object p,q,r,and s separately for the member function only one memory location which is allocated in the definition.

Posted Date: 9/20/2012 7:55:04 AM | Location : United States







Related Discussions:- Memory allocation for objects, Assignment Help, Ask Question on Memory allocation for objects, Get Answer, Expert's Help, Memory allocation for objects Discussions

Write discussion on Memory allocation for objects
Your posts are moderated
Related Questions

How would you print the values of the variables words and lines so they appear in the form: There were 6040 words and 680 lines. Here, 6040 and 680 represent the values of the two

write a javaprogram to solve padovan string using java? program in java // aakash , suraj , prem sasi kumar kamaraj college program 1 : package test.padovanstring;

array of class objects and single inheritance

There is a pebble merchant. He sells the pebbles, that are used for shining the floor. His main duty is to take the length of the room’s sides. But he sometimes mistakes doing that

1.1 A Few Notes: 1. Please test your program with various inputs prior to submission. 2. All group members must understand the entire project for interactive grading. Equal

Description - The TR-069 CPE WAN Management Protocol (CWMP) is a protocol that was created by the Broadband Forum (formally the DSL Forum) which sets out a common method for CPE de

Cross Platform Clinet app for a vpn Project Description: We want a cross platform client app for VPN. The app must have the subsequent options below: 1. Must be an open

d) a "static destructor" is a static member function of the class which accepts one argument - a pointer to the object of that class to be cracked. It is probably utilized along wi