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
Define the Recursion Function in C? In C, it is potential for the function to call themselves a function is describing 'recursive' if a statement within the body of a function

Write an algorithm to print all even numbers in descending order and draw the flowchart.

Ask question #Minimum 100Problem : Compiler Design - Limit the methods Rahul is a newbie to the programming and while learning the programming language he came to know the followi

C Program for FUNCTION OF COUNT THE INTEREST float si(float,float,float); void main() {           float p=0,r=0,n=0,k=0;           clrscr();           printf("E

Create a program WordCount1Main.java doing the following:  For each word in the le word.txt { Create an object of the class Word { Add the object to a set of the type java.uti

Explain Register Variable Computers have internal registers, which are used to keep data temporarily, before any operation can be performed. Intermediate results of the calcula

how to create the programs in c++ knowledge

what is classes?

Using Figure 10.2 as a model, illustrate the result of each operation in the sequence ENQUEUE.Q; 4/, ENQUEUE.Q; 1/, ENQUEUE.Q; 3/, DEQUEUE.Q/, ENQUEUE.Q; 8/, and DEQUEUE.Q/ on an i

padovan string problem program 1 : package test.padovanstring; public class PadovanString {     public int stringOccurrences(int n, String str){        if(n >= 40)