PROMOTE MY BLOG: JUST CLICK BELOW BUTTON

Search Any Paper On This Blog

Thursday, March 3, 2011

CS201 Solved Subjectiev Questions

By ADEEL ABBAS, Bhakkar. AdeelAbbasbk@gmail.com
malloc Function
malloc is used to dynamically allocate memory in the C programming language. malloc returns a pointer of type void to a memory buffer of a requested size, or null if it fails. It may also be used in C++, although new is preferred.

 The malloc function takes one argument i.e. the number of bytes to be allocated. The

realloc Function Sometimes, we have allocated a memory space for our use by malloc function. But we see later that some additional memory is required. For example, in the previous example, where (for example) after allocating a memory for 35 students, we wanted to add one more student. So we need same type of memory to store the new entry. Now the question arises ‘Is there a way to increase the size of already allocated memory chunk ? Can the same chunk be increased or not? The answer is yes. In such situations, we can reallocate the same memory with a new size according to our requirement. The function that reallocates the memory is realloc. The syntax of realloc is given below. void realloc (void * ptr, size_t size ) ;


constructor
A function called when a class object comes into scope. The constructor is used to initialize the object. See allocation, copy constructor, and destructor.

Date::Date(int theDay, int theMonth, int theYear)
{
 day = theDay;
 month = theMonth;
 year = theYear;

 }
Default arguments with constructors
We can also use the default arguments with the constructors. In the case of Date,
normally the days and months are changing and the year remains same for one year.
So we can give the default value to year.

Date::Date(int theDay, int theMonth, int theYear = 2002)
{
// The body of the constructor
}


Object
In C++, often refers to an instance of a class. Also more loosely refers to any named declaration of a variable or other entity that involves storage.

No comments:

Post a Comment

PLEASE COMMENT ABOUT YOUR VISIT AND MY SITE

Note: Only a member of this blog may post a comment.