Tuesday, 15 July 2014

What is Memory Allocation ? A Simple Answer.



MEMORY ALLOCATION ( DYNAMIC OR STATIC)


It all starts from a data that is stored in the memory , that data is given some memory .This Process of Giving memory is Called a memory allocation . The memory can be allocated in two manners : DYNAMICALLY AND STATICALLY .

STATIC MEMORY ALLOCATION 

-This memory allocation process reserves fixed mount of memory before actual processing takes place , and because of that , the number of elements to be stored must be predetermined . 
Such memory allocation process is  basically called as static memory allocation .

-The Arrays are allocated memory by this process only.


DYNAMIC MEMORY ALLOCATION

-This Type of memory allocation process gives allocation of memry during the program execution itself, as and when it is needed.This process of allocating memory is called  dynamic memory allocation .
-It also provides technique to release the memory , when memory is not required anymore.

-Data structures like Linked Lists and Tress use this very technique for their memory allocation.

Basics of Linked Lists , Stacks And Queues In C++


Linked Lists , Stacks And Queues


The very basic definitions that a person should know who is learning C++ are :

Linked ListsIT IS A  LINEAR COLLECTION OF DATA ELEMENTS , CALLED AS NODES POINTING TO THE NEXT NODES BY MEANS OF POINTER.

Stacks :  A STACK IS A LINEAR  STRUCTURE IMPLEMENTED IN LIFO (LAST IN FIRST OUT )MANNER WHERE INSERTION AND DELETIONS ARE  RESTRICTED TO OCCUR ONLY AT ONE END - THAT END IS SATCK'S TOP.

Queues: A QUEUE IS  ALSO A LINEAR DYNAMIC STRUCTURE IMPLEMENTED IN FIFO( FIRST IN FIRST OUT) MANNER WHERE INSERTIONS CAN OCCUR AT THE " REAR ' END  , AND THE BASIC DELETIONS OCCUR ONLY AT " FRONT" END.


IMPORTANT POINTS 

LIFO

-Means Element last inserted would be the first one to be deleted.

-The Stack is also  a DYNAMIC DATA STRUCTURE as it can grow( //with increase in number of elements //) or it can shrink(//with decrease in number of elements //).

FIFO:

-Means elements are deleted  in the same order as they are inserted into the queue.

Tuesday, 1 July 2014

Significance of access specifiers in a class in C++.



Significance of access specifiers in  a class


In C++ a class provides three access labels namely , private, protected and public.

A member declared as private or protected in C++ remains hidden from world and it can only be accessed by the member functions of the class itself. 

A member declared as public in C++ program is made available to the outside world. Basically it can accessed by any member functions of the class , by nay expression in the program but only by using a object of the same class type.

The labels listed enforces the data hiding  and abstraction, oop concepts  in C++ 

Compare default arguments and function overloading.




Compare default arguments and function overloading.


In C++ with the default arguments , the default values can be provided in the function prototype itself and the that function can be called even if the arguments are missing.
But there is one thing that should be considered that is , if you want to default a middle argument then all the arguments on its right must be defaulted.

And on the other side of this , you can overload a function for all possible argument combinations . It basically overcomes the limitation of default arguments but also the compiler is saved from the problem of testing the default value and pushing it on the function call stack. So with that compiler can process another thing.

Basic Concept of Function Overloading With Example


Concept of Function Overloading With Example


The very basic definition of function overloading in C++ is a function name having several definition that are differentiable by the number or the types of their arguments , is known as function overloading.


For Example 

The following example in which the code overloads a function area to find the values of area of circle ,rectangle and triangle.


float area(float r)
{
return 3.1*r*r;
}
float area (float len,float bre)
{
return len*bre;
}
float area(float side1, float side2, float side3)
{
float & = (side1+side2+side3)/2;
float ar = sqrt(&*(&_side1)*(&*(&_side2)*(&*(&_side3));
return ar;
}