Register | Sing In

New posts

Stacks in C programming Linked Lists in C programming File Input/Output in C programming Check prime numbers in C Programming C Programming Enumeration C Programming Union

Archives

2013-10 2013-09 2013-08

Increment and Decrement Operators in C programming

August 13, 2013 Posted by: GPA Views: 1220 0 comments

C also provides the unary increment operator, ++, and the unary decrement operator, --

If a variable "a" is incremented by 1, the increment operator ++ is used rather than the expressions a = a + 1 or a += 1.

 Increment and decrement operators are in table below.

Operator Sample expression Explanation
++ ++a Increment value a by 1,then use the new value of a in the expression in which a resides.
++ a++
Use the current value of a in the expression in which a resides, then increment a by 1.
--
--a Decrement a by 1, then use the new value of a in the expression in which a resids.
-- a-- Use the current value of variable a in the expression in which a resides, then decrement a by 1.

Example:

 

  
#include <stdio.h>
#include <stdlib.h>
//main function
int main(int argc, char *argv[]){
   
int a=10;
   printf("a = %d",a);
    ++a;
    printf("\na after increment by 1 = %d",a);
    a++;
    printf("\na after increment by 1 = %d",a);
    --a;
   printf("\na after decrement by 1 = %d",a);
    a--;
   printf("\na after decrement by 1 = %d\n",a);
   system("PAUSE");//delay
    return 0;
}

Output

Download this example

0 Comments...

Leave a Reply

Please, Sing In to leave a Reply for this material.



Online Chat

LiveZilla Live Help

Popular posts

Function strtok in C programming Check prime numbers in C Programming C Programming Union Linked Lists in C programming File Input/Output in C programming C Programming Enumeration

RSS-subscribe

New materials

Subscribe