运算符重载不影响运算符优先级,赋值是要特别注意先后顺序!i 输出结果分析

#include /**

C对变量操作++
int i=10;
++在前 先++后运算
++i = 20; 等价 i=i+1;i=11+20;i=31;

++在后 先赋值后运算
i++ = 20; 等价 i=i+20; i=30; 当再次使用的时候会对i加1
**/

int main()
{
int i = 10;
++i = 20;
printf("%d\n",i);

int j = 10;
j++ = 20;
printf("%d\n",j);
printf("%d\n",j+0);

return 0;
}

 

---------------------------------------------------------

 

// class.cpp : 定义控制台应用程序的入口点。

#include "stdafx.h"
#include
#include
using namespace std; //stdin stdout stderr


class CmyClass_Str
{
public:
unsigned char ucaVocationType[5];
unsigned char ucaAppFlag[5];
unsigned char ucaVarCheck[5];
CmyClass_Str(){}
~CmyClass_Str(){}


};
CmyClass_Str class_center;


int _tmain(int argc, _TCHAR* argv[])
{
unsigned char ucTemp[20]="";
int i=0;


memcpy(class_center.ucaVocationType, "01", 2);
memcpy(class_center.ucaAppFlag,"01", 2);
memcpy(class_center.ucaVarCheck, "4631", 4);
memcpy(ucTemp+(i+=0), class_center.ucaVocationType, 2);
memcpy(ucTemp+(i+=2), class_center.ucaAppFlag,2);
memcpy(ucTemp+(i+=2), class_center.ucaVarCheck,4);

cout<<"ucTemp ["<

cout<<"_________________i="< cout<<"double i++"<<"\tcout< cout<<"i is\t"<
cout<<"_________________i="< cout<<"double ++i"<<"\tcout< cout<<"i is\t"<<++i<<"\tNow i is\t"<<++i<
cout<<"_________________i="< cout<<"double i--"<<"\tcout< cout<<"i is\t"<
cout<<"_________________i="< cout<<"double --i"<<"\tcout< cout<<"i is\t"<<--i<<"\tNow i is\t"<<--i< Sleep(3);
return 0;
}
 

你可能感兴趣的:(各种,杂项,C++)