-->

program to get sum of two numbers using pointer

using codeblocks
----------------------------------------------------------------------
//sum of two numbers using pointer     //comment of program
#include <stdio.h>                     //header file
int main()
{
    int *p,*p1;                      //two pointer declaration
    int x,y;                           //variable declaration
    printf("enter two values for x and y\n");//prints message
    scanf("%d%d",&x,&y);                    // gets input
    p=&x,p1=&y;                        //assigning address to that pointer
    printf("the address of x(%d) is=%d\n",x,p);//display of that address
    printf("the address of y(%d) is=%d\n",y,p1);//display of address of second variable
    printf("the sum=%d\n",*p+*p1); 
 //display of sum stored in that address. we display that using indirection operator
    return 0;
}
-----------------------------------------------------------------------------------------------
using turboc++
------------------------------------------------------------------------------------------
//sum of two numbers using pointer     //comment of program
#include <stdio.h>                     //header file
#include<conio.h>
int main()
{
    int *p,*p1;                      //two pointer declaration
    int x,y;                           //variable declaration
    printf("enter two values for x and y\n");//prints message
    scanf("%d%d",&x,&y);                    // gets input
    p=&x,p1=&y;                        //assigning address to that pointer
    printf("the address of x(%d) is=%d\n",x,p);//display of that address
    printf("the address of y(%d) is=%d\n",y,p1);//display of address of second variable
    printf("the sum=%d\n",*p+*p1);    
//display of sum stored in that address. we display that using indirection operator
    getch();
    return 0;
}


Program to show pointer for increment and decrement operator.

using codeblocks
---------------------------------------------------------------------------

//understanding pointer  increment and decrement              //comment of program
#include <stdio.h>                     //header file
int main()
{
    int *pointer;                      //pointer declaration
    int x=4;                           //value assignment
    pointer=&x;                        //assigning address to that pointer
    printf("the address of x is=%d\n",pointer);//display of that address
    printf("the  value of x=%d\n",*pointer);    //display of value stored in that address. we display that using indirection operator
   pointer++;                             //increment of address by 1
   printf("pointer ++=%d\n",pointer);       //display of that address
   pointer--;                            //pointer decrement
   printf("pointer --=%d",pointer);       //display of that address

    return 0;
}


-------------------------------------------------------------------------------------------------------------
using turboc++
----------------------------------------------------------------------------------------------------------
//understanding pointer  increment and decrement              //comment of program
#include <stdio.h>                     //header file
#include<conio.h>
int main()
{
    int *pointer;                      //pointer declaration
    int x=4;                           //value assignment
    pointer=&x;                        //assigning address to that pointer
    printf("the address of x is=%d\n",pointer);//display of that address
    printf("the  value of x=%d\n",*pointer);    //display of value stored in that address. we display that using indirection operator
   pointer++;                             //increment of address by 1
   printf("pointer ++=%d\n",pointer);       //display of that address
   pointer--;                            //pointer decrement
   printf("pointer --=%d",pointer);       //display of that address
  getch();                                           //to hold the output
    return 0;
}

Program to show a character pointer

using codeblocks
-------------------------------------------------------------------------

//understanding pointer for a character             //comment of program
#include <stdio.h>                     //header file
int main()
{
    char *pointer;                      //pointer declaration of character type
    char x='a';                           //value assignment of character type
    pointer=&x;                        //assigning address to that pointer
    printf("the address of x is=%d\n",pointer);//display of that address
    printf("the  value of x=%c",*pointer);   
//display of value stored in that address. we display that using indirection operator
    return 0;
}

---------------------------------------------------------------------------------------------
using turbo c++
------------------------------------------------------------------------------------------
//understanding pointer for a character             //comment of program
#include <stdio.h>                     //header file
#include<conio.h>
int main()
{
    char *pointer;                      //pointer declaration of character type
    char x='a';                           //value assignment of character type
    pointer=&x;                        //assigning address to that pointer
    printf("the address of x is=%d\n",pointer);//display of that address
    printf("the  value of x=%c",*pointer);   
 //display of value stored in that address. we display that using indirection operator
   getch();
    return 0;
}

Program to show use of pointer.

using codeblocks
----------------------------------------------------------------------------------------

//understanding pointer                //comment of program
#include <stdio.h>                     //header file
int main()
{
    int *pointer;                      //pointer declaration
    int x=4;                           //value assignment
    pointer=&x;                        //assigning address to that pointer
    printf("the address of x is=%d\n",pointer);//display of that address
    printf("the  value of x=%d",*pointer);    //display of value stored in that address. we display that             using indirection operator
    return 0;
}

------------------------------------------------------------------------------------
using tuboc++
--------------------------------------------------------------------------------------
//understanding pointer                //comment of program
#include <stdio.h>                     //header file
#include<conio.h>
int main()
{
    int *pointer;                      //pointer declaration
    int x=4;                           //value assignment
    pointer=&x;                        //assigning address to that pointer
    printf("the address of x is=%d\n",pointer);//display of that address
    printf("the  value of x=%d",*pointer);    
//display of value stored in that address. we display that using indirection operator
   getch();
    return 0;
}

program to show total bytes used by union ,using sizeof().

using codeblocks
-------------------------------------------------------------------------
//sizeof  union with some data
#include <stdio.h>                         //header file
union det                                  //union tag
{
    char name[30];                      //first member
    char address[70];                   //second member
    int roll_no;                        //third member
}acc;                                   //data variable
int main()
{
    printf("total  SIZE=%d",sizeof(acc));//prints total bytes occupied by variable 'acc'.
    return 0;
}

//note: it finds the sum of all members with the largest one and other.
-------------------------------------------------------------------------------------------------------

using turbo c++
----------------------------------------------------------------------------------------------
//sizeof  union with some data
#include <stdio.h>                         //header file
#include<conio.h
union det                                  //union tag
{
    char name[30];                      //first member
    char address[70];                   //second member
    int roll_no;                        //third member
}acc;                                   //data variable
int main()
{
    printf("total  SIZE=%d",sizeof(acc));//prints total bytes occupied by variable acc.
    getch();
    return 0;
}



program to initialize union

using codeblocks
----------------------------------------------------------------------------------

This does not work!
---------------------------------

//initializing  union with some data
#include <stdio.h>                         //header file
#include<string.h>
union det                                  //union tag
{
    char name[70];                      //first member
    char address[70];                   //second member
}acc={"rajan","KTM"};                   //initializing data
int main()
{
    printf("the name is ");
    puts(acc.name);                    //puts data on screen i.e. name
    printf("the address is\n");
    puts(acc.address);                  //puts data on screen but does not get displayed on screen
    return 0;
}
// we have tried to access both members at same time.
//so, We get same data "rajan" two times. We do not get "KTM".
----------------------------------------------------------------------------------------------------------------

This works!
-------------------------------------------------------

//initializing  union with some data
#include <stdio.h>                         //header file
#include<string.h>                         //handles strings
union det                                  //union tag
{
    char name[70];                      //first member
    char address[70];                   //second member
}acc;                                //data variable
int main()
{
    strcpy(acc.name,"Rajan");         //data initialization and being copied to 'name'
    printf("the name is ");
    puts(acc.name);                    //puts data on screen i.e. name
    strcpy(acc.address,"KTM");         //data initialization and being copied to 'address'
    printf("the address is\n");
    puts(acc.address);                  //puts data on screen but does not get displayed on screen
    return 0;
}
// we have  accessed one member at a  time.
//so, We get different data "rajan" then ktm.
---------------------------------------------------------------------------------------------------------------
using turbo c++
----------------------------------------------------------------------------------------------
//initializing  union with some data
#include <stdio.h>                         //header file
#include<string.h>                         //handles strings
#include<conio.h>                        //header file
union det                                  //union tag
{
    char name[70];                      //first member
    char address[70];                   //second member
}acc;                                //data variable
int main()
{
    strcpy(acc.name,"Rajan");         //data initialization and being copied to 'name'
    printf("the name is ");
    puts(acc.name);                    //puts data on screen i.e. name
    strcpy(acc.address,"KTM");         //data initialization and being copied to 'address'
    printf("the address is\n");
    puts(acc.address);                  //puts data on screen but does not get displayed on screen
    getch();
     return 0;
}
// we have  accessed one member at a  time.
//so, We get different data "rajan" then ktm.


program show use of union with input and output.

using codeblocks
-----------------------------------------------------------------------------------------------------------
//understanding union with simple input and output
#include <stdio.h>                         //header file
union det                                  //union tag
{
    char name[70];                      //first member
    char address[70];                   //second member
}acc;
int main()
{
    printf("enter name\n");
    gets(acc.name);                    //gets input for name
    printf("the name is ");
    puts(acc.name);                    //puts data on screen
    printf("enter address\n");
    gets(acc.address);                  //gets address
    printf("the address is ");
    puts(acc.address);                  //puts data on screen
    return 0;
}

Note:-
// we can input one member at a time so, We have input first member only then second member and so on.
// If we input input all members at same time, It would get crashed and give unexpected result
------------------------------------------------------------------------------------------------------
using turbo c++
--------------------------------------------------------------------------------------------------------
//understanding union with simple input and output
#include <stdio.h>                         //header file
#include<conio.h>                      //header file to hold output
union det                                  //union tag
{
    char name[70];                      //first member
    char address[70];                   //second member
}acc;
int main()
{
    printf("enter name\n");
    gets(acc.name);                    //gets input for name
    printf("the name is ");
    puts(acc.name);                    //puts data on screen
    printf("enter address\n");
    gets(acc.address);                  //gets address
    printf("the address is ");
    puts(acc.address);                  //puts data on screen
    getch();                                  //holds output
    return 0;
}
// we can input one member at a time so, We have input first member only then second member and so on.
// If we input input all members at same time, It would get crashed and give unexpected result