Saturday, 26 May 2012

argument pass in function

 Arguments in function are passed in two ways
  1. Call by value
  2. Call by reference
Call by value : In this method we just pass value of variable in function . so that any change in these values never affect our main value.

  Reason: In this case we passed values that are assigned to new function variables. So if we do any modification applied to function variable not main's variable.

  #include<stdio.h>
   void add(int a, int b)
   int main()
   {
      int i=2 , int j =5;
      add(i,j);
      getch();
    }
   void add(int a, int b)
   {
     a++;
     b++;
   }





here we are passing values of i and j in the function. and change in function never affect to main 's value (i and j).


Call by reference : In this method we just pass address of variable in function. so that any change affect our main value.

Reason: In this case we passed address that are assigned to new function pointer variables whose task to provide alternative way to reach original value in the memory. So if we do any modification applied main's variable

  #include<stdio.h>
   void add(int *a, int *b)
   int main()
   {
      int i=2 , int j =5;
      add(&i,&j);
      getch();
    }
   void add(int *a, int *b)
   {
     *a++;
     *b++;
   }


  


   here we are passing address of i and j in the function. and change in function affect to main 's value (i and j).
  

overview of functions

function is a way through which we separate our code into different sections. this functionality gives power to reuse that section again and again anywhere in code.

Situation :  In our community we have different profile for people that works as designation for them like doctor, engineer, worker etc. All these work in different section. but whenever we need any one of them we can take help from them.

Point we get   above situation we can apply in programming that's know as function. because all works as a different designation. Same we can define functions for use of different purpose and according to our need we call any  function at any time.


Parts of function : we need to use three basic rule to define a function in c-language.

  1. function prototype 
  2. function call
  3. function body
Function prototype : This part works as function declaration in programming. This step works as registration .

As we want to participate in any function. Before going there we need to inform them.
this step in programming called function prototype or function declaration.

Pattern
                         return type  function-name(function-arguments);
         

return-type: what value we want to return from function
                 
                          int          ----------  for integer
                          char      ----------   for character
                          float      ----------   for float 
                          void       ----------   for not returning values

function-arguments this step tell what parameter we want to pass to function and values are passed as simple variable declaration form.


                            void  add(int a ,int b);

 Function Call  This step is used to call a function. It is used to in following manner.

  Pattern          
                        function-name(arguments);
                        add(a,b);

Function body  This step is used to define how this function work . In this part we define whole purpose of function .

 Pattern 
                      return-type  function-name(arguments)
                      {


                      }


from above discussion we study about basic rule how to define and use function in our programming.

Example : 

Addition of two number without function

   #include<stdio.h>
   int main()
   { 
      int i=2 , int j =5;
      c=i+j;
      printf("addition of i and j is \t");
      printf("%d\n",c);
      i=10;
      j=20;
      c=i+j;
      printf("addition of i and j is \t");
      printf("%d\n",c);
      i=100;
      j=200;
      c=i+j;
      printf("addition of i and j is \t");
      printf("%d\n",c);
     
      getch();
   }

Here if want add two number with different values we need to repeat same type of code again and again . which is wastage of programming logic. so how we resolve this situation.
  
Addition of two number using function

   #include<stdio.h>
   void add(int a, int b)
   int main()
   { 
      int i=2 , int j =5;
      add(i,j);
      i=10;
      j=20;
      add(i,j);
      getch();
    }
   void add(int a, int b)
   {
     int c;
     c=a+b;
     printf("%d",c);
   }


Friday, 25 May 2012

gets and puts function

Situation : suppose we have list of students . And we need to enter their name. As normal no. of character in each name varies . So We can't use looping for storing values in string because looping runs till string size.


Similarly we want to enter space among different words. using normal input functions it's not possible.
Unformatted  String Input  function


If we want to enter a paragraph where we don't know expected word length then  formatted input function we can't use. For this purpose we we following function.
  1. gets() for input
  2. puts() for output


gets() function

We use this function for storing a string value in memory. using this we don't need to use looping. and this function doesn't bound us about memory.
syntex
         char str[size];
         gets(str);

int main()
{
    char str[10];
    printf("enter value of str  ");
    gets(str);
    printf("\n value of str is \t ");
    printf("%s",str);
  }

Input      enter value of  str  minty ji
          
Output   value of str is       minty

What's this output here. this happen because %s doesn't print after space. So how to handle this situation.


Solution:  Use puts() function. This function print every things untill enter character hit.


puts() function

We use this function for printing a single character value. 

syntex
         puts(str);

int main()
{
    char str[10];
    printf("enter value of str  ");
    gets(str);
    printf("\n value of str is \t ");
    puts(str);
  }

Input      enter value of  str  minty ji
          
Output   value of str is       minty ji


Read latest blog 

putch() and putchar() function

Unformatted single character output function


putch() function

We use this function for printing a single character value. 

syntex
    
         putch(char variable);

int main()
{
    char ch;
    printf("enter value of ch  ");
    ch =getch();
    printf("\n value of ch is \t ");
    putch(ch);
}

Input      enter value of ch a 
                  then don't need to hit enter
Output   value of ch is        a




putchar() function

We use this function for printing a single character value. 

syntex
    
         putchar(char variable);

int main()
{
    char ch;
    printf("enter value of ch  ");
    ch =getch();
    printf("\n value of ch is \t ");
    putchar(ch);
}

Input      enter value of ch a 
                  then don't need to hit enter
Output   value of ch is        a

Read latest blog

basic of getch() and getche() function

getch() function

We use this function for storing a single character value in variable. 

syntex
    
         char ch;
         ch=getch();

int main()
{
    char ch;
    printf("enter value of ch  ");
    ch =getch();
    printf("\n value of ch is \t");
    printf("%c",ch);
}

Input      enter value of ch a 
                  then don't need to hit enter
Output   value of ch is        a


This is simple implementation of getch() function. We can't enter more than one character using getch() function.
Points

  1. we don't need to hit enter after input .

getche() function

We use this function for storing a single character value in variable. 

syntex
    
         char ch;
         ch=getche();
int main()
{
    char ch;
    printf("enter value of ch  ");
    ch =getche();
    printf("\n value of ch is \t");
    printf("%c",ch);
}

Input      enter value of ch (input always invisible)
                 then don't need to hit enter
Output   value of ch is        a


This is simple implementation of getche() function. We can't enter more than one character using getche() function.
Points

  1. we don't need to hit enter after input .
  2.  In case of getche() function we can't see input values



input and output in detail

C language provides two basic method for input and output.

  1. Formatted I/O function
  2. Unformatted I/O function
Formatted I/O function

In this category printf() and scanf() comes. Because we need a specific format for I/O.
we  study above functions.

Unformatted I/O function

In this category getch(), getchar(), getche(), gets() comes for Input.

putch(), putchar(), puts() comes for Output.

Because we don't need any specific format for using these function.

getchar() function

We use this function for storing a single character value in variable. 

syntex
    
         char ch;
         ch=getchar();
program

int main()
{
    char ch;
    printf("enter value of ch  ");
    ch =getchar();
    printf("\n value of ch is \t");
    printf("%c",ch);
}

Input      enter value of ch a then hit enter
Output   value of ch is        a


This is simple implementation of getchar() function but if we enter more character in input
ex

Input      enter value of ch school then hit enter

In the above case first value stored in variable ch while other stored in buffer of computer. Which are automatically assigned to next character variable .


Example


int main()
{
    char ch,ch2;
    printf("enter value of ch  ");
    ch =getchar();
    ch2=getchar();
    printf("\n value of ch and ch2 is \t");
    printf("%c %c",ch,ch2);
}

Input      enter value of ch school then hit enter
Output   value of ch and ch2 is       sc
Points

  1. we need to hit enter after input .
  2. if we enter more than one character at time of input then first is stored in variable while other are stored in buffer memory.
  3. values in buffer memory automatically  assigned to next char input variable.
























Tuesday, 22 May 2012

subtraction in matrix

For learning  matrix subtraction you must study my blog about two dimensional  array. 

In last tutorial we learn how to declare two dimensional array. Here i gave you concept  how to subtract two matrix.

first matrix is 

  int m1[3][3];

second matrix is 

  int m2[3][3];

Third matrix is 

int m3[3][3];

                     m3                                             m1                                                m2

              col0    col1   col2                   col0    col1    col2               col0    col1    col2
                 
row0     ---        ---      ---         row0    ---        ---        ---      row0    ---        ---        ---    

  
row1    ---        ---      ---          row1    ---        ---        ---      row1    ---        ---        ---
 
row2    ---        ---      ---          row2    ---        ---     ---          row2    ---        ---     ---



-------------------------------------------------------------------------------------------------------------------------------


from above scenario

 (0,0) of m1 always subtract  (0,0) of m2 and stores in (0,0) of m3

  so in c language

    m3[0][0]=m1[0][0]-m2[0][0]

similarly

(0,1) of m1 always subtract  (0,1) of m2 and stores in (0,1) of m3

    m3[0][1]=m1[0][1]-m2[0][1]

similarly

(0,2) of m1 always subtract  (0,2) of m2 and stores in (0,2) of m3

    m3[0][2]=m1[0][2]-m2[0][2]


here we notice that row is constant means 0 but column varies 0,1,2
   
    so   for(col=0;col<3;col++)
           { 

 
                m3[0][col]=m1[0][col]-m2[0][col] ]


            }
------------------------------------------------------------------------------------------------------------------------------- 

second row of matrix

(1,0) of m1 always subtract  (1,0) of m2 and stores in (1,0) of m3

  so in c language

    m3[1][0]=m1[1][0]-m2[1][0]

similarly

(1,1) of m1 always subtract  (1,1) of m2 and stores in (1,1) of m3

    m3[1][1]=m1[1][1]-m2[1][1]

similarly

(1,2) of m1 always subtract  (1,2) of m2 and stores in (1,2) of m3

    m3[1][2]=m1[1][2]-m2[1][2]


here we notice that row is constant means 1 but column varies 0,1,2
   
    so   for(col=0;col<3;col++)
           { 

 
                m3[1][col]=m1[1][col]-m2[1][col] ]


            }
------------------------------------------------------------------------------------------------------------------------------- 
                               

third row of matrix


(2,0) of m1 always subtract  (2,0) of m2 and stores in (2,0) of m3

  so in c language

    m3[2][0]=m1[2][0]-m2[2][0]

similarly

(2,1) of m1 always subtract  (2,1) of m2 and stores in (2,1) of m3

    m3[2][1]=m1[2][1]-m2[2][1]

similarly

(2,2) of m1 always subtract  (2,2) of m2 and stores in (2,2) of m3

    m3[2][2]=m1[2][2]-m2[2][2]


here we notice that row is constant means 2 but column varies 0,1,2
   
    so   for(col=0;col<3;col++)
           { 

 
                m3[2][col]=m1[2][col]-m2[2][col] ]


            }
------------------------------------------------------------------------------------------------------------------------------- 
              

  anyone got idea what i want to say. Yes Here we repeating similar loop row 0, row 1
  row2 . We have some way to reduce this task . How it is possible.

   Solution :
               using second loop out side the column .
 
         for(row=0;row<3;row++)
         {
               for(col=0;col<3;col++)
              { 

 
                  m3[row][col]=m1[row][col]-m2[row][col] ]

               }

          }







matrix additional in c

For learning  matrix addition you must study my blog about two dimensional  array. 

In last tutorial we learn how to declare two dimensional array. Here i gave you concept  how to add two matrix.

first matrix is 

  int m1[3][3];

second matrix is 

  int m2[3][3];

Third matrix is 

int m3[3][3];

                     m3                                             m1                                                m2

              col0    col1   col2                   col0    col1    col2               col0    col1    col2
                 
row0     ---        ---      ---         row0    ---        ---        ---      row0    ---        ---        ---    

  
row1    ---        ---      ---          row1    ---        ---        ---      row1    ---        ---        ---
 
row2    ---        ---      ---          row2    ---        ---     ---          row2    ---        ---     ---



-------------------------------------------------------------------------------------------------------------------------------


from above scenario

 (0,0) of m1 always add  (0,0) of m2 and stores in (0,0) of m3

  so in c language

    m3[0][0]=m1[0][0]+m2[0][0]

similarly

(0,1) of m1 always add  (0,1) of m2 and stores in (0,1) of m3

    m3[0][1]=m1[0][1]+m2[0][1]

similarly

(0,2) of m1 always add  (0,2) of m2 and stores in (0,2) of m3

    m3[0][2]=m1[0][2]+m2[0][2]


here we notice that row is constant means 0 but column varies 0,1,2
   
    so   for(col=0;col<3;col++)
           { 

   
                m3[0][col]=m1[0][col]+m2[0][col] ]


            }
------------------------------------------------------------------------------------------------------------------------------- 

second row of matrix

(1,0) of m1 always add  (1,0) of m2 and stores in (1,0) of m3

  so in c language

    m3[1][0]=m1[1][0]+m2[1][0]

similarly

(1,1) of m1 always add  (1,1) of m2 and stores in (1,1) of m3

    m3[1][1]=m1[1][1]+m2[1][1]

similarly

(1,2) of m1 always add  (1,2) of m2 and stores in (1,2) of m3

    m3[1][2]=m1[1][2]+m2[1][2]


here we notice that row is constant means 1 but column varies 0,1,2
   
    so   for(col=0;col<3;col++)
           { 

   
                m3[1][col]=m1[1][col]+m2[1][col] ]


            }
------------------------------------------------------------------------------------------------------------------------------- 
                               

third row of matrix


(2,0) of m1 always add  (2,0) of m2 and stores in (2,0) of m3

  so in c language

    m3[2][0]=m1[2][0]+m2[2][0]

similarly

(2,1) of m1 always add  (2,1) of m2 and stores in (2,1) of m3

    m3[2][1]=m1[2][1]+m2[2][1]

similarly

(2,2) of m1 always add  (2,2) of m2 and stores in (2,2) of m3

    m3[2][2]=m1[2][2]+m2[2][2]


here we notice that row is constant means 2 but column varies 0,1,2
   
    so   for(col=0;col<3;col++)
           { 

   
                m3[2][col]=m1[2][col]+m2[2][col] ]


            }
------------------------------------------------------------------------------------------------------------------------------- 
              

  anyone got idea what i want to say. Yes Here we repeating similar loop row 0, row 1
  row2 . We have some way to reduce this task . How it is possible.

   Solution :
               using second loop out side the column .
  
         for(row=0;row<3;row++)
         {
               for(col=0;col<3;col++)
              { 

   
                  m3[row][col]=m1[row][col]+m2[row][col] ]

               }

          }







two dimensional array in c-lang

Pattern :    
                     data type   array name[rows][cols];

example   int roll[3][3];

this declaration creates following memory scenario.

                                   col0                col1              col2
               
    row0                      -----                   ----                  -----

 
    row1                     -----                   -----                  -----


    row2                     ----                     ----                   -----


Accessing this array


Most confusing thing in two dimensional array is how to access it's elements.

-------------------------------------------------------------------------------------------------------------------------------


 Now i am giving it's answer in following way

 In maths if we want to access row0,col0 data then we use(0,0)

  in  case of c language  we access   array_name[row_number][col_number]

   so (0,0)   in c language      roll[0][0]

  if we want to access row0,col1 data then we use(0,1)

   so (0,1)   in c language      roll[0][1]

  if we want to access row0,col2 data then we use(0,2)

   so (0,2)   in c language      roll[0][2]

   using for loop we can access directly. What you notice here  

    row is constant means 0 but column varies 0,1,2
   
    so   for(col=0;col<3;col++)
           { 

    
             do your task using roll[0][col]


            }

 -------------------------------------------------------------------------------------------------------------------------------

  In maths if we want to access row1,col0 data then we use(1,0)


  so (1,0)   in c language      roll[1][0]


  if we want to access row1,col1 data then we use(1,1)

   so (1,1)   in c language      roll[1][1]

  if we want to access row1,col2 data then we use(1,2)

   so (1,2)   in c language      roll[1][2]


   similarly  for row 1 and column 0,1,2

           for(col=0;col<3;col++)
           { 

    
             do your task using roll[1][col]


            }

   what's this thing we just need to change only row rest is same

-------------------------------------------------------------------------------------------------------------------------------


  In maths if we want to access row2,col0 data then we use(2,0)


  so (2,0)   in c language      roll[2][0]


  if we want to access row2,col1 data then we use(1,1)

   so (2,1)   in c language      roll[2][1]

  if we want to access row2,col2 data then we use(1,2)

   so (2,2)   in c language      roll[2][2]

   similarly  for row 2 and column 0,1,2


           for(col=0;col<3;col++)
           { 

    
             do your task using roll[2][col]


            }

  -------------------------------------------------------------------------------------------------------------------------------

  anyone got idea what i want to say. Yes Here we repeating similar loop row 0, row 1
  row2 . We have some way to reduce this task . How it is possible.

   Solution :
               using second loop out side the column .
   
         for(row=0;row<3;row++)
         {
               for(col=0;col<3;col++)
              { 

    
                do your task using roll[row][col]


               }

          }
   


what this thing. It simply repeat column loop for each row . This way we can use          two  dimensional array.
-------------------------------------------------------------------------------------------------------------------------------






Read latest blog







Monday, 21 May 2012

Pointer in c language

Pointer is a variable that store address of another variable but same type so that we can access data of  first (normal) variable. 

Situation: suppose a postman delivers letters in a city. He know where is address. Someday he is on leave. So What happen with delivery of letters. Post office appoint new postman temporary and he delivered letters for that day.



Conclusion: We must have second way to reach that address .

This mechanism is also applied with programming language. Where we have second way to access variables using pointer.

Q. question is how this is done ?
A. Simple as pointer definition it is used to store address of another variable. This phenomena we use to make second way to reach that address.

Task first  how pointer declared ?

                   datatype * variable name;

                 this declare a pointer variable.

Task second how to assign address to pointer of another variable ?

                 pointer variable= & normal variable;

     
                  using address of operator we assign address of normal variable to pointer.

Task third  how to access  value of normal variable using pointer ?

                  using  *pointer variable;




               above pattern tells the pointer that go it's stored address and access normal variable value. 


example
                  int i=10;
                  int  *ptr;
                  ptr=&i;
                  access value using *ptr;


























Sunday, 20 May 2012

array with memory

Array stores in contiguous memory  where each element in array have equal size of  memory because it is collection of similar type of data.

If we want to know about memory location of any element, it is find out on the basis of base (starting) element of array. 

Situation 1

This situation is like train where we can consider it's engine as base element and can reach any compartment of it. Because we know starting of this chain. 

Situation 2

We have a street on which each house is equal in size. Address of first house is A-1 and we want to reach A-4 . So how it is possible. 
first we need to reach at A-1 and then  A-2 .....A-4.




Conclusion

  Compiler never remember all elements address. It know only starting address of array element and reach  or access any element on the basis of it.

                              size=2              size=2                size=2              size=2       
                         [element 1]--->[element 2]--->[element 3]--->[element 4]

                          Address 1         Address 2         Address 3        Address 4

If we assume  starting address of  element 1 is 1000 then what's about address 2. can we assume. It's simple like reaching A-1 to A-2 . We simply add size of element 1 to starting address. Means 
 
Address of element 1  is  1004                   = Address 1
Address of element 2  is  1000+2 = 1004 = Address 2
Address of element 3  is  1004+2 = 1006 = Address 3
Address of element 4  is  1006+2 = 1008 = Address 4

Result : compiler reaches to new element on the basis of base element. It simple adds size of element to base address. Size of element is vary and based on data type. that is


Character   1  byte
Integer        2  byte
Float             4  byte  



















how to access array elements

Array is collection of similar type of data stored in contiguous memory. Here i will show how array is mapped in memory.Let's suppose we have array of students roll
numbers .

int  student_roll[4];

Above line creates four spaces in memory.



 where first element is called base element of array and named following syntex

                                            arrayname[index]

here index denotes position of element. In memory array starts from 0 index. So
base element is   student_roll[0]
similarly

second element is  student_roll[1]
third element is      student_roll[2]
and fourth element is student_roll[3]

we can access all elements using concept of  looping
int i;

for(i=0;i<4;i++)
{
   code for printf() or scanf() using student_roll[i]
}

here i works as counter who count index of array.

Input in array

for putting data in memory we use scanf() function.

putting data at base(first) element    scanf("%d",&student_roll[0]);

putting data at second element           scanf("%d",&student_roll[1]);
putting data at third  element             scanf("%d",&student_roll[2]);

putting data at forth element              scanf("%d",&student_roll[3]);

Using looping

for(i=0;i<4;i++)
{
  scanf("%d",&student_roll[i]);
}



Output in array

for getting data from memory we use printf() function.

getting data from base(first) element    printf("%d",student_roll[0]);

getting data from second element           printf("%d",student_roll[1]);
getting data from third  element             printf("%d",student_roll[2]);

getting data from forth element              printf("%d",student_roll[3]);




Using looping


for(i=0;i<4;i++)
{
  printf("%d",student_roll[i]);
}



 thus we learn how to access elements of array for input and output purpose.


Read latest blog




















array in c language

Situation:  We have class of 5o students and we need to store roll number of each student in memory. As we discussed that for storing data in memory we need a variable. So for storing rollnumber of 50 students we need 50 different variables.

If number of students increase need more variable. So If we need roll number of all students in a university. Then we don't imagine how many variable we need.

Solution :  For these type of situation concept of array comes. Where we need to store similar type of data (in above situation roll number). 

Array  is a  collection of similar type ( int, char, float etc.) of data in contiguous memory.

Q. What's meaning of contiguous memory ?

It's simple. Understanding this we need to assume one situation

We can think array as a train who has lots of compartment at it's back side.Where each compartment is situated one after another. Means one by one.

Same thinking apply for array's contiguous memory where each new element comes one after another.



Pattern for Array

        datatype  arrayname[size];
         
  1.  datatype says which type of data(int, char, float) we want to store in array.
  2.  size tells how many data we want in array.

 example
 
  for storing  roll number of  50 students
      int rollnumber[50];

This declaration automatically create 50 spaces in memory like above diagram where
each space in situated one after another(contiguous memory).


Read latest blog















while and do while loop in c language



Situation

We have two hotel one is charging money for first time entry and second is not charging  money for  first time for entry.
  1. Charging money is a condition to enter in the hotel for first time and anyone who can afford this can enter in the hotel.
  2. While in second case there is no charge for first time entry.  
Above both situations are applied with while and do-while. In case of while if we want to enter in loop we need to satisfied condition but in case of do-while we don't have condition for entry in loop at first time.  

while structure is 


        initialization
        while(condition)
        {
      
          your code;


         increment/decrement;
        }

do-while structure is 

        initialization
        do{



              your code ;
              increment/decrement;
         }while(condition);

Concept for  while and do-while looping is same as for loop.

Read latest blog
 


Saturday, 19 May 2012

Looping in c language and use of for loop

Looping is a way through which we execute similarly types of statement again and again.

Example : In car racing racer have same track to practice. So they use it again and again for practice means make a definite loop which has a start point and  a end point and how many times they want to practice it.

Example :  We have a mobile on which we set alarm. Alarm starts at fix time and stop also on fix time. Between start and end time alarm tune always same. That's  why  alarm tune sounded at that interval.

Any loop has a start point                      --------> called  initialization in programming.
Study last post about looping
 Initialization is a process through which we start loop from a certain point.

Example : we need to count ten bats. We can start our counting from any number
  1 or 10 or -10 or any other so this is called our start point. Same as loop has a start point.

Any loop has a end point                      --------> called  condition in programming.

Condition is end point of loop where we expect to stop.

Example : As after starting our counting we stop at any definite point.

  if  starts from 1 we stop at 10.
  if  starts from 10 we stop at 19.
  same as if starts from -10 we stop at -1.
  this is called end condition of loop.
  
Travel between start and end point   ----> called increment and decrement  of loop

As we starts from 1  then we go to 2 then 3 and so on...means we are incrementing value
Similarly if we starts from -10 we go -9 then -8 and so on...means we are decrementing value.

loop's life cycle
   


 As from above flow we can learn that

  1. At first step loop goes to initialization part.
  2. At second step loop check condition.
  3. At third step loop perform increment and decrement task.
  4. If condition comes false loop quite and comes outside


Read latest blog
 

input and output in c language

Computer is a machine which need some input as these input it gives some output to us.
Example : We have bike. We fill patrol in it as input as result  it run. similarly we need some input in computer programming . As  input it process and produce some output.

study previous blog

In c language we  use in built functions for input and output.

Input : Input is a process through which we assign values to variable. For taking input
we use scanf() function of c library. It's task to store data in memory that can be use for any purpose in programming.

Pattern   
                     scanf("%x",&variablename);
                      %x ---------> %c  for  character
                      %x ---------> %d  for  Integer
                      %x ---------> %f   for  float
here & is address of operator which gives address of any variable.

 

Output : Output is a process through which we print value of any variable. for taking output we use printf() function of c library. It's task to print value on computer screen.

Pattern
      
                      printf("%x", variablename);
                      %x ---------> %c  for  character
                      %x ---------> %d  for  Integer
                      %x ---------> %f   for   float
using printf() function we can print both value and address of any variable in c language.


Read latest blog

Friday, 18 May 2012

variable storage in memory

As i discussed that we can assume variable as house which provide storage for us.
Read basic understanding of variables in c language

So every house  has a address through which we can reach there. Same mechanism is
applied for variable in memory. Every variable has address in memory that is managed by  programming language.




Again every house has a particular specified area. This mechanism we apply for variable size. Every variable has a fixed amount of size provided by programming language as in c-language (Turbo compiler) it is
  1 byte for character
  2 bytes for integer
  4 bytes for float



Read latest blog

basic understanding of variables in c language

For understanding variables in c language we need to assume a situation that we live in world. we all are human.but every one has different name and surname. We divided ourself into category.Similarly data(name,id,any value) in computer is a group which is divide into different types. And each type is given a name. Which is called as character,integer,float etc. from above discussion we conclude that

Variables is a form to represent information in any programming language. which provide a way to store data in memory.
from above diagram we can see we have data that belongs to different category like
some data is whole number and some is decimal number and some is character or string. According to it we divides data into type.
  1. Integer 
  2. Float 
  3. Character
Example : We live in house.So house is a variable which provide a storage for us. As house can be in different style which define it's type. Similarly variable is a storage place for data in computer memory but as house is in different style variable have different type.  



  1. Integer:  It is way to represent whole number in programming language.
  2. Float:  It is way to represent decimal values in programming language.
  3. Character:  It is way to represent alphabetic and non-alphabetic data in programming language.