Program to find the maximum number between two numbers using a pointer.

Here, we have a basic program example find the maximum number using pointers in C and C++.

Code to fine the maximum number in C language

#include <stdio.h>
#include <stdlib.h>
void main()
{
 int num1,num2,*ptr1=&num1,*ptr2=&num2;
   printf(" Input the first number : ");
   scanf("%d", ptr1);
   printf(" Input the second  number : ");
   scanf("%d", ptr2);
 if(*ptr1>*ptr2)
 {
  printf("\n\n %d is the maximum number.\n\n",*ptr1);
 }
 else
 {
  printf("\n\n %d is the maximum number.\n\n",*ptr2);
 }
}

Code to fine the maximum number in C++ language

#include<iostream>
using namespace std;
int main()
{
    int first,second,*num1,*num2;
    num1=&first;
    num2=&second;
    cout<<"Enter first number"<<endl;
    cin>>first;
    cout<<"Enter second number"<<endl;
    cin>>second;
    if(*num1>*num2){
      cout<<"Largest="<<*num1<<" and smallest="<<*num2<<endl;
     }
    else{
        cout<<"Largest="<<*num2<<" and smallest="<<*num1<<endl;
    }
return 0;
}