C Tutorial/Operator/Increment decrement Operator — различия между версиями
Admin (обсуждение | вклад) м (1 версия: Импорт контента...) |
|
(нет различий)
|
Текущая версия на 10:32, 25 мая 2010
Increment operator
Prefix: the value is incremented/decremented first and then applied.
Postfix: the value is applied and the value is incremented/decremented.
#include<stdio.h>
main( )
{
int i = 3,j = 4,k;
k = i++ + --j;
printf("i = %d, j = %d, k = %d",i,j,k);
}
i = 4, j = 3, k = 6
The decrement operator: --
#include <stdio.h>
#include <stdlib.h>
int main()
{
char weight[4];
int w;
printf("Enter your weight:");
gets(weight);
w=atoi(weight);
printf("Here is what you weigh now: %i\n",w);
w--;
printf("w++: %i\n",w);
w--;
printf("w++: %i\n",w);
return(0);
}
Enter your weight:123 Here is what you weigh now: 123 w++: 122 w++: 121