C++运算符优先级 案例1

问:

              ...

              short nReaderCount=10
              ++pLock->nReaderCount==?

              ...

++和->同为1级优先级,我想很多也有很多新手弄不清楚这个例子先执行   ++    操作,还是先执行的  ->   操作

我自己写个了短程序:

              #include<iostream>
              using namespace std;
             

              class test
              {
              public:
                  short nReaderCount;
              };

              int main()
              {
                  test *test1=new test;
                  test1->nReaderCount=10;
    
                  cout<<    ++test1->nReaderCount    <<endl;
                  cout<<"结果表明:先执行指针操作,再执行自增操作";

              return 0;
              }

追问:如果test是union 那么结果又是什么?

原文地址:https://www.cnblogs.com/azbane/p/7613569.html