程序師世界是廣大編程愛好者互助、分享、學習的平台,程序師世界有你更精彩!
首頁
編程語言
C語言|JAVA編程
Python編程
網頁編程
ASP編程|PHP編程
JSP編程
數據庫知識
MYSQL數據庫|SqlServer數據庫
Oracle數據庫|DB2數據庫
 程式師世界 >> 編程語言 >> C語言 >> 關於C語言 >> C++學習筆記--研究生期間持續更新,學習筆記--

C++學習筆記--研究生期間持續更新,學習筆記--

編輯:關於C語言

C++學習筆記--研究生期間持續更新,學習筆記--


1. post-increment and pre-increment 的區別

來源:http://www.c4learn.com/c-programming/c-increment-operator/

#include<stdio.h>

void main()
{
int a,b,x=10,y=10;

a = x++;
b = ++y;

printf("Value of a : %d",a);
printf("Value of b : %d",b);
}

Different Types of Increment Operation

In C Programming we have two types of increment operator i.e Pre-Increment and Post-Increment Operator.

A. Pre Increment Operator

Pre-increment operator is used to increment the value of variable before using in the expression. In the Pre-Increment value is first incremented and then used inside the expression.

b = ++y;

In this example suppose the value of variable ‘y’ is 5 then value of variable ‘b’ will be 6 because the value of ‘y’ gets modified before using it in a expression.

B. Post Increment Operator

Post-increment operator is used to increment the value of variable as soon as after executing expression completely in which post increment is used. In the Post-Increment value is first used in a expression and then incremented.

b = x++;

In this example suppose the value of variable ‘x’ is 5 then value of variable ‘b’ will be 5 because old value of ‘x’ is used.

  1. 上一頁:
  2. 下一頁:
Copyright © 程式師世界 All Rights Reserved