基于C++輸出指針自增(++)運算的示例分析
更新時間:2013年05月27日 17:30:13 作者:
本篇文章是對C++中輸出指針自增(++)運算的示例進行了詳細的分析介紹,需要的朋友參考下
復(fù)制代碼 代碼如下:
#include "stdafx.h"
#include <iostream>
using namespace std;
int _tmain(int argc, _TCHAR* argv[])
{
char s[] = "012345678", *p = s;
cout << "s:"<<s<<endl;
cout << "*p++ = " << *p++ << ", *(p++) = " << *(p++) << ", (*p)++ = " << (*p)++ << ", *++p = " << *++p << ", *(++p) = "<< *(++p) << ", ++*p = " << ++*p << ", ++(*p) = "<< ++(*p) << endl;
cout<<"-------------------"<<endl;
char s1[] = "012345678";
p = s1;
cout << endl << "s1:"<<s1<<endl;
cout << "*p = " << *p <<endl;
cout << "*p++ = " << *p++ << endl;
cout << "*p = " << *p <<endl;
cout << "*(p++) = " << *(p++) << endl;
cout << "*p = " << *p <<endl;
cout << "(*p)++ = " << (*p)++ << endl;
cout << "*p = " << *p <<endl;
cout << "*++p = " << *++p << endl;
cout << "*p = " << *p <<endl;
cout << "*(++p) = " << *(++p) <<endl;
cout << "*p = " << *p <<endl;
cout << "++*p = " << ++*p << endl;
cout << "*p = " << *p <<endl;
cout << "++(*p) = " << ++(*p) <<endl;
cout<<"-------------------"<<endl;
system("pause");
return 0;
}
輸出:
s:012345678
*p++ = 3, *(p++) = 3, (*p)++ = 2, *++p = 4, *(++p) = 4, ++*p = 4, ++(*p) = 4
-------------------
s1:012345678
*p = 0
*p++ = 0
*p = 1
*(p++) = 1
*p = 2
(*p)++ = 2
*p = 3
*++p = 3
*p = 3
*(++p) = 4
*p = 4
++*p = 5
*p = 5
++(*p) = 6
-------------------
請按任意鍵繼續(xù). . .
相關(guān)文章
C++ 數(shù)據(jù)結(jié)構(gòu)實現(xiàn)兩個棧實現(xiàn)一個隊列
這篇文章主要介紹了詳解C++ 數(shù)據(jù)結(jié)構(gòu)實現(xiàn)兩個棧實現(xiàn)一個隊列的相關(guān)資料,需要的朋友可以參考下2017-03-03Qt學(xué)習筆記之QPalette調(diào)色板類
這篇文章主要為大家詳細介紹了Qt學(xué)習筆記之QPalette調(diào)色板類,文中示例代碼介紹的非常詳細,具有一定的參考價值,感興趣的小伙伴們可以參考一下2019-07-07