variables in c cpp internal concepts rarely known

                            Variables in C & CPP 

well now we come to the basic that is variables in C AND CPP

variables - basically variables are used to store values given by the user

for being specific and dividing variables into types we have

1)valued variable 

2)reference variable 

3)buffer variable

1) valued variable - in value variable user stores the values 

    such as for eg. int v =10

    This means  allocate two byte memory and store the value 10 in it.

2) reference variable - here we can store the reference   of  the other variable 

     basically this reference comes from the registry memory used to refer  other

variables

  for eg.    int a;

               int *p;

p can store the address of other  variable

so we can write according to syntax

p=&a;

Note:for a declaration of pointer declare a pointer of that data type of which variables address u  want to store.

The main thing is to be noted that in memory everything works  on address

so by pointer variable we are providing for direct address .

 

See friends basic process happening inside it is that when we want to access the variable the two virtual memory comes into picture 

1) stack 

2)heap

case 1:  if not declared pointer ........

every time the control goes to registry memory and sees the address and then goes to stack memory for taking the value of that variable every time.

 

case 2:if declared pointer then.......

The cost of going into the registry will be eliminated.

as we are providing the direct address through pointer.

so the execution becomes faster as compared to first case...

 

                    variables storage in c and cpp basic concept

1)stack : - in stack the variables are stored in the order bottom to top.

                variables in c  are stored all in stack.

 

2)heap:- well in heap the variables are stored from top to bottom

              well for the concept of class came into picture

              in class we have an object to access the methods and members  ..

             objects contains the collection of variables of different data type 

             variables of class are stored in heap and the corresponding .

  note:- for reference variable they are stored in RAM that is why the other 

            cause for faster execution is this concept

           And fix 2 byte is allocated for pointer variable....

 

hope this would be useful to broaden your concept  ....!!!

 

 

 

 

 

 

 

 

  

Comments

Popular posts from this blog

Navigation in Vaadin.

Drag and drop items from one Grid to another

State space search / blocks world problem by heuristic approach /TIC TAC TOE