cout中的执行顺序_a++和++a

时间:2023-06-01 18:28:56

printf和cout从右到左计算:

int main()
{
/*
char* str = NULL;
setmemory(&str, 100);
strcpy(str, "hello");
cout << str << endl;
*/
int arr[] = {,,,,};
// int* ptr = arr;
int* mp = arr;
// *(++ptr) += 123; //arr[1] = 130
cout << *mp << " " << *(mp++) << " " << *mp << endl;   //6 6 7
  cout << *mp << " " << *(++mp) << " " << *mp << endl; //6 7 7
cout << *mp << endl;
// printf("%d,%d,%d", *ptr,*(ptr++),*ptr);
// cout << *ptr << endl << *(++ptr) << endl;
return ;

a++和++a都是先自增,区别在于a++自增后将自增前的值通过临时变量返回。