Â
In this, we are going to see a program is based on Incrementing and Decrementing an Integer, using pointer.The Code given below can be used in TURBO C++ Compilers: -
#include <stdio.h>
#include<conio.h>
void main()
{
clrscr();
int a;
int *pt;
cout << "Incrementing and Decrementing an Integer:\n";
a = 1;
pt = &a;
(*pt)++; //Post Increment
cout << "\n[a++]:Increment Value of A = " << a;
++(*pt); //Pre Increment
cout << "\n[++a]:Increment Value of A = " << a;
(*pt)--; //Post Decrement
cout << "\n[a--]:Decrement Value of A = " << a;
--(*pt); //Pre Decrement
cout << "\n[--a]:Decrement Value of A = " << a << endl;
getch();
}
//...........Coded by Rishab Nair
The Code given below can be used in gcc/g++ Compilers: -
#include <iostream>
using namespace std;
int main()
{
int a;
int *pt;
cout << "Incrementing and Decrementing an Integer:\n";
a = 1;
pt = &a;
(*pt)++; //Post Increment
cout << "\n[a++]:Increment Value of A = " << a;
++(*pt); //Pre Increment
cout << "\n[++a]:Increment Value of A = " << a;
(*pt)--; //Post Decrement
cout << "\n[a--]:Decrement Value of A = " << a;
--(*pt); //Pre Decrement
cout << "\n[--a]:Decrement Value of A = " << a << endl;
return 0;
}
//...........Coded by Rishab Nair
#ENJOY CODING
Post a Comment
FOR ANY DOUBTS AND ERRORS FEEL FREE TO ASK. YOUR DOUBTS WILL BE ADDRESSED ASAP