-->

program to input elements of array and display them using pointer.

using codeblocks
-------------------------------------------------------------------------------------------
//program to input elements for an array and display using pointer //comment of program
#include <stdio.h>            //header file

int main()                   //main function
{
    int *p;                   //pointer declaration
    int a[20],i;
    int total;
    printf("enter total number\n");
    scanf("%d",&total);            // gets total value of array.
    p=a;                        //stores base address
    for(i=0;i<total;i++)      //runs from 0 to one less than total
    {
        scanf("%d",p+i);   //gets value for given address. This input goes upto last value of address
    }
    printf("values are\n");
    for(i=0;i<total;i++)
    {
        printf("%d\n",*(p+i));//displays its value with the help of address
    }
    return 0;
}

---------------------------------------------------------------------------------------------------
or
-------------------------------------------------------------------------------------------------------------------
//program to input elements for an array and display using pointer //comment of program
#include <stdio.h>            //header file

int main()                   //main function
{
 
    int a[20],i;
    int total;
    printf("enter total number\n");
    scanf("%d",&total);            // gets total value of array.
   //p=a;                        //stores base address
    for(i=0;i<total;i++)      //runs from 0 to one less than total
    {
        scanf("%d",a+i);   //gets value for given address. This input goes upto last value of address
                                     //array itself is a pointer. It accepts value for first location and so on.
    }
    printf("values are\n");
    for(i=0;i<total;i++)
    {
        printf("%d\n",*(a+i));//displays its value with the help of address
    }
    return 0;
}



------------------------------------------------------------------------------------------------------------------
using turboc++
------------------------------------------------------------------------------------------------------
//program to input elements for an array and display using pointer //comment of program
#include <stdio.h>            //header file
#include<conio.h>
int main()                   //main function
{
    int *p;                   //pointer declaration
    int a[20],i;
    int total;
    printf("enter total number\n");
    scanf("%d",&total);            // gets total value of array.
    p=a;                        //stores base address
    for(i=0;i<total;i++)      //runs from 0 to one less than total
    {
        scanf("%d",p+i);   //gets value for given address. This input goes upto last value of address
    }
    printf("values are\n");
    for(i=0;i<total;i++)
    {
        printf("%d\n",*(p+i));//displays its value with the help of address
    }
getch();
    return 0;
}

program to understand call by value and call by reference

using codeblocks
--------------------------------------------------------------------------------
// call by value reference
#include <stdio.h>
void callbyref(int*, int*);             /* function Prototype with two pointer as parameter*/

int main()                            /* Main function */
{
  int x = 10, y = 20;                 //variable declaration

    printf("before calling\n");                         /* actual arguments will be altered */
  printf("x=%d,y=%d\n",x,y);        //value display before call
  callbyref(&x, &y);              // passing address
  printf("after calling\n");
  printf("x= %d, y= %d\n", x, y);   //displaying value after calling
  return 0;
}

void callbyref(int *m, int *n)
{
  int t;
  t = *m;
  *m = *n;
  *n = t;                       //swapping being done
}


----------------------------------------------------------------------------------------------
using turbo c++
-----------------------------------------------------------------------------------------
// call by value reference
#include <stdio.h>
#include<conio.h>
void callbyref(int*, int*);             /* function Prototype with two pointer as parameter*/

int main()                            /* Main function */
{
  int x = 10, y = 20;                 //variable declaration

    printf("before calling\n");                         /* actual arguments will be altered */
  printf("x=%d,y=%d\n",x,y);        //value display before call
  callbyref(&x, &y);              // passing address
  printf("after calling\n");
  printf("x= %d, y= %d\n", x, y);   //displaying value after calling
 getch();
  return 0;
}

void callbyref(int *m, int *n)
{
  int t;
  t = *m;
  *m = *n;
  *n = t;                       //swapping being done
}