-->

Program to find factorial value of a number using pointer.

using codeblocks
---------------------------------------------------------------------------
//program to get factorial value of a number using pointer
#include <stdio.h>            //header file
int main()
{
    int i,facto=1;                //variable initialization
    int number;                   //variables declaration
    int *p;                      //pointer declaration
    printf("enter a number\n");
    scanf("%d",&number);              //input of a number
    p=&number;                             //storing of address to pointer
    for(i=1;i<=*p;i++)                   //execution of loop till the value reaches to last
    {
        facto=facto*i;                   //continuous multiplication

    }
        printf("factorial value=%d",facto);       //display of output
    return 0;
}

------------------------------------------------------------------------------------------------------------------
using turbo c++
----------------------------------------------------------------------------------------------------------------
//program to get factorial value of a number using pointer
#include <stdio.h>            //header file
#include<conio.h>
int main()
{
    int i,facto=1;                //variable initialization
    int number;                   //variables declaration
    int *p;                      //pointer declaration
    printf("enter a number\n");
    scanf("%d",&number);              //input of a number
    p=&number;                             //storing of address to pointer
    for(i=1;i<=*p;i++)                   //execution of loop till the value reaches to last
    {
        facto=facto*i;                   //continuous multiplication

    }
        printf("factorial value=%d",facto);       //display of output
     getch();
    return 0;
}

Program to input 20 numbers and pick the greatest one using pointer.

using codeblocks
------------------------------------------------------------------------------------------------------
//program to pick the greatest number using pointer
#include <stdio.h>            //header file

int main()
{
    int a[100];                 //array declaration
    int i,max;
    int total;                   //variables declaration
    int *p;                      //pointer declaration
    printf("enter value of total\n");
    scanf("%d",&total);              //input of total value of array
    printf("enter elements of array\n");
    p=a;                             //storing of base address to pointer
    for(i=0;i<total;i++)                   //execution of loop
    {
        printf("enter value for location=%d\t",i);
        scanf("%d",p+i);                  //input of element using pointer. here array's base address is used for input
                                          //It gets input using address starting from base location 0.
                                          //It goes on increasing (address) as the loop moves ahead.
    }
    max=*(p+0);                          //It stores value stored in location 0
    for(i=0;i<total;i++)
    {
       if(max<*(p+i))                   //comparison takes place
       {
         max=*(p+i);                    //assigning value
       }
    }
    printf("max value=%d",max);       //display of maximum value
    return 0;
}
--------------------------------------------------------------------------------------------------------
using turbo c++
-------------------------------------------------------------------------------------------------------
//program to pick the greatest number using pointer
#include <stdio.h>            //header file
#include<conio.h>
int main()
{
    int a[100];                 //array declaration
    int i,max;
    int total;                   //variables declaration
    int *p;                      //pointer declaration
    printf("enter value of total\n");
    scanf("%d",&total);              //input of total value of array
    printf("enter elements of array\n");
    p=a;                             //storing of base address to pointer
    for(i=0;i<total;i++)                   //execution of loop
    {
        printf("enter value for location=%d\t",i);
        scanf("%d",p+i);                  //input of element using pointer. here array's base address is used for input
                                          //It gets input using address starting from base location 0.
                                          //It goes on increasing (address) as the loop moves ahead.
    }
    max=*(p+0);                          //It stores value stored in location 0
    for(i=0;i<total;i++)
    {
       if(max<*(p+i))                   //comparison takes place
       {
         max=*(p+i);                    //assigning value
       }
    }
    printf("max value=%d",max);       //display of maximum value
getch();   
return 0;
}


Program to input 20 numbers and pick the greatest one using pointer.

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

//Program to input 20 numbers and pick the greatest one using pointer.
#include <stdio.h>            //header file
int main()
{
    int a[100];                 //array declaration
    int i,max;
    int total;                   //variables declaration
    printf("enter value of total\n");
    scanf("%d",&total);              //input of total value of array
    printf("enter elements of array\n");
    for(i=0;i<total;i++)                   //execution of loop
    {
        printf("enter value for location=%d\t",i);
        scanf("%d",a+i);                  //input of element using array. here array acts as pointer.
                                          //It gets input using address starting from location 0.
    }
    max=*(a+0);                          //It stores value stored in location 0
    for(i=0;i<total;i++)
    {
       if(max<*(a+i))                   //comparison takes place
       {
         max=*(a+i);                    //assigning value
       }
    }
    printf("max value=%d",max);       //display of maximum value
    return 0;
}
-------------------------------------------------------------------------------------------------------------
using turbo c++
----------------------------------------------------------------------------------------------------------
//program to pick the greatest number using pointer
#include <stdio.h>            //header file
#include<conio.h>
int main()
{
    int a[100];                 //array declaration
    int i,max;
    int total;                   //variables declaration
    printf("enter value of total\n");
    scanf("%d",&total);              //input of total value of array
    printf("enter elements of array\n");
    for(i=0;i<total;i++)                   //execution of loop
    {
        printf("enter value for location=%d\t",i);
        scanf("%d",a+i);                  //input of element using array. here array acts as pointer.
                                          //It gets input using address starting from location 0.
    }
    max=*(a+0);                          //It stores value stored in location 0
    for(i=0;i<total;i++)
    {
       if(max<*(a+i))                   //comparison takes place
       {
         max=*(a+i);                    //assigning value
       }
    }
    printf("max value=%d",max);       //display of maximum value
getch();   
 return 0;
}


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
}

program to understand array of pointer

using codeblocks
---------------------------------------------------------------------------------------------------------
//understanding array of pointers  for numbers     //title of program
#include <stdio.h>                    //header file

int main()
{
    int a[4],i;
    int *p[4];                        //pointer to store 4 addresses
    printf("enter array elements\n");
    for(i=0;i<=3;i++)
    {
        printf("enter element for location %d\n",i);
        scanf("%d",&a[i]);           // gets array elements
    }
    printf("the addresses are\n");
    for(i=0;i<=3;i++)
    {
        p[i]=&a[i];                 // stores address of element of array
        printf(" location =%d and address=%d\n",i,p[i]);//prints the address
    }
    printf("the values are\n");
    for(i=0;i<=3;i++)
    {
        p[i]=&a[i];                 // stores address of element of array
        printf(" location =%d and address=%d\n",i,*p[i]);//prints the value
    }
    return 0;
}

---------------------------------------------------------------------------------------
using turbo c++
-----------------------------------------------------------------------------------------
//understanding array of pointers  for numbers     //title of program
#include <stdio.h>                    //header file
#include<conio.h>

int main()
{
    int a[4],i;
    int *p[4];                        //pointer to store 4 addresses
    printf("enter array elements\n");
    for(i=0;i<=3;i++)
    {
        printf("enter element for location %d\n",i);
        scanf("%d",&a[i]);           // gets array elements
    }
    printf("the addresses are\n");
    for(i=0;i<=3;i++)
    {
        p[i]=&a[i];                 // stores address of element of array
        printf(" location =%d and address=%d\n",i,p[i]);//prints the address
    }
    printf("the values are\n");
    for(i=0;i<=3;i++)
    {
        p[i]=&a[i];                 // stores address of element of array
        printf(" location =%d and address=%d\n",i,*p[i]);//prints the value
    }
getch();
    return 0;
}

program to use 2d array/string to display address and values.

using codeblocks
---------------------------------------------------------------------------------------------------
//understanding array of pointers  for strings     //title of program
#include <stdio.h>                    //header file
int main()
{
     char *a[4];                      //pointer to store 4 addresses
    int i;
    char naam[4][6];                   //2d array of string
    printf("enter array elements\n");
    for(i=0;i<=3;i++)
    {
        printf("enter name for location %d\n",i);
        scanf("%s",naam[i]);                            // gets array elements
    }

    printf("the addresses are\n");
    for(i=0;i<=3;i++)
    {
         a[i]=&naam[i];                                // stores address of element of array
        printf(" location =%d and address=%d\n",i,a+i);//prints the address
    }
    printf("the values are\n");
    for(i=0;i<=3;i++)
    {
        a[i]=&naam[i];                                 // stores address of element of array
        printf(" location =%d and name=%s\n",i,*(a+i));//prints the stored value
    }
    return 0;
}

//note:-
//1. in 2d string of array, a=naam does not work. We have to work manually by assigning address as shown above.
//we can not print values or addresses using a[i]. it does not work.
-----------------------------------------------------------------------------------------------------
using turbo c++
---------------------------------------------------------------------------------------------------
//understanding array of pointers  for strings     //title of program
#include <stdio.h>                    //header file
#include<conio.h>                  //header file
int main()
{
     char *a[4];                      //pointer to store 4 addresses
    int i;
    char naam[4][6];                   //2d array of string
    printf("enter array elements\n");
    for(i=0;i<=3;i++)
    {
        printf("enter name for location %d\n",i);
        scanf("%s",naam[i]);                            // gets array elements
    }

    printf("the addresses are\n");
    for(i=0;i<=3;i++)
    {
         a[i]=&naam[i];                                // stores address of element of array
        printf(" location =%d and address=%d\n",i,a+i);//prints the address
    }
    printf("the values are\n");
    for(i=0;i<=3;i++)
    {
        a[i]=&naam[i];                                 // stores address of element of array
        printf(" location =%d and name=%s\n",i,*(a+i));//prints the stored value
    }
   getch();
    return 0;
}

//note:-
//1. in 2d string of array, a=naam does not work. We have to work manually by assigning address as shown above.
//we can not print values or addresses using a[i]. it does not work.