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

printf和cout从右到左计算:

int main()
{
/*
    char* str = NULL;
    setmemory(&str, 100);
    strcpy(str, "hello");
    cout << str << endl;
*/
    int arr[] = {6,7,8,9,10};
//    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 0;

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

posted @ 2016-10-06 12:40  Lunais  阅读(928)  评论(0)    收藏  举报