
- C Programming Tutorial
- C - Home
- C - Overview
- C - Environment Setup
- C - Program Structure
- C - Basic Syntax
- C - Data Types
- C - Variables
- C - Constants
- C - Storage Classes
- C - Operators
- C - Decision Making
- C - Loops
- C - Functions
- C - Scope Rules
- C - Arrays
- C - Pointers
- C - Strings
- C - Structures
- C - Unions
- C - Bit Fields
- C - Typedef
- C - Input & Output
- C - File I/O
- C - Preprocessors
- C - Header Files
- C - Type Casting
- C - Error Handling
- C - Recursion
- C - Variable Arguments
- C - Memory Management
- C - Command Line Arguments
- C Programming useful Resources
- C - Questions & Answers
- C - Quick Guide
- C - Useful Resources
- C - Discussion
Write a C program to demonstrate post increment and pre increment operators
Increment operator (++)
It is used to increment the value of a variable by 1. There are two types of increment operators, pre-increment and post-increment.
The increment operator is placed before the operand in pre-increment and the value is first incremented and then the operation is performed on it.
For example,
z = ++a; a= a+1 z=a
The increment operator is placed after the operand in post-increment and the value is incremented after the operation is performed.
For example,
z = a++; z=a a= a+1
Example 1
Following is an example for pre-increment operator −
main ( ){ int A= 10, Z; Z= ++A; printf ("Z= %d", Z); printf (" A=%d", A); }
Output
Z =11 A=11
Example 2
Following is an example for post-increment operator −
main ( ){ int a= 10, z; z= a++; printf ("Z= %d", z); printf ("A=%d", a); }
Output
Z=10 A=11
Decrement operator (- -)
It is used to decrement the values of a variable by 1. There are two types of increment operators, pre decrement and post decrement.
The decrement operator is placed before the operand in pre decrement and the value is first decremented and then the operation is performed on it.
For example,
z = - - a; a= a-1 z=a
The decrement operator is placed after the operand in post decrement and the value is decremented after the operation is performed
For example,
z = a--; z=a a= a-1
Example 1
Following is an example for pre decrement operator −
main ( ){ int a= 10, z; z= --a; printf ("Z= %d", z); printf (" A=%d", a); }
Output
Z=9 A=9
Example 2
Following is an example for post decrement operator −
main ( ){ int a= 10, z; z= a--; printf ("Z= %d", z); printf ("A=%d", a); }
Output
Z=10 A=9
- Related Articles
- Pre-increment and Post-increment in C/C++
- Pre-increment and Post-increment concept in C/C++?
- Pre & post increment operator behavior in C, C++, Java, and C#
- Pre-increment (or pre-decrement) in C
- Increment ++ and decrement -- Operators in C++
- Increment and Decrement Operators in C#
- Python Increment and Decrement Operators
- PHP Increment/Decrement Operators
- What are increment (++) and decrement (--) operators in C#?
- Increment and decrement operators in Java
- Increment and Decrement Operators in Python?
- Why avoid increment (“++”) and decrement (“--”) operators in JavaScript?
- Interesting facts about Increment and Decrement operators in Java
- What are the restrictions on increment and decrement operators in java?
- Way to increment a character in C#
