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
Write a function that has four unsigned char parameters, combines the four one-byte integer values into an unsigned integer, and returns the unsigned integer. When the four one

Write a program to calculate the timetable for numbers 1 -> 10 and display them as follows. Your solution should use for do loops      #include stdio.h void main() {    char p

Describe the “placement new" and why would I use it?

i have a project that is due this Wednesday and i was wondering if i can get help in doing it?

C Program for FUNCTION OF FIND THE FACTORIAL float factorial(float); void main() {           float i=0,c=0;           clrscr();           printf("ENTER THE DIGI

#questionHi, I am looking for help with the assignment, can you help..


Write a program to find the area under the curve y = f(x) between x = a and x = b, integrate y = f(x) between the limits of a and b. The area under a curve betw

padovan string c++ program

Write a program to count the prime number in array