Prefix and postfix increment and decrement in C++ (C Plus Pls)

Prefix and postfix increment and decrement in C++ (C Plus Pls)

In this latest tutorial, we will try to cover the following topics;

  1. Prefix increment and post fix  increment in C++ (C Plus Pls)
  2. Prefix decrement and post fix  decrement in C++ (C Plus Pls)

Prefix increment and post fix  increment in C++ (C Plus Pls)

// Prefix increment and post fix  increment in C++ (C Plus Pls)
#include <iostream>
using namespace std;
int main()
{
int a,b,c,d;
a=b=0;
d=c=0;
a=b++; //post fix
c=++d;  //pree fix
cout<<“a=”<<a<<endl<<“b=”<<b<<endl;
cout<<“c=”<<c<<endl<<“d=”<<d<<endl;
}

Output

postfix prefix increment in C++ (C Plus Plus)
Figure: postfix prefix increment in C++ (C Plus Plus)

Prefix deccrement and post fix  decrement in C++ (C Plus Pls)

// Prefix deccrement and post fix  decrement in C++ (C Plus Pls)
#include <iostream>
using 
d=c=0;namespace std;

int main()
{
int a,b,c,d;
a=b=0;
a=b–;  //post fix decrement
c= –d;  //pree fix decrement
cout<<“a=”<<a<<endl<<“b=”<<b<<endl;
cout<<“c=”<<c<<endl<<“d=”<<d<<endl;
}

Output

postfix prefix decrement in C++ (C Plus Plus)
Figure: postfix prefix decrement in C++ (C Plus Plus)
Prof. Fazal Rehman Shamil
Researcher, Publisher of International Journal Of Software Technology & Science ISSN: 2616-5325
Instructor, SEO Expert, Web Programmer and poet.
Feel free to contact.