基于C++輸出指針自增(++)運(yùn)算的示例分析
更新時(shí)間:2013年05月27日 17:30:13 作者:
本篇文章是對(duì)C++中輸出指針自增(++)運(yùn)算的示例進(jìn)行了詳細(xì)的分析介紹,需要的朋友參考下
復(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
-------------------
請(qǐng)按任意鍵繼續(xù). . .
您可能感興趣的文章:
- C++ 自增、自減運(yùn)算符的重載和性能分析小結(jié)
- 淺談C++類(lèi)型轉(zhuǎn)化(運(yùn)算符重載函數(shù))和基本運(yùn)算符重載(自增自減)
- 詳解C++賦值操作符重載
- C++-操作符重載、并實(shí)現(xiàn)復(fù)數(shù)類(lèi)詳解
- 詳解C++-(=)賦值操作符、智能指針編寫(xiě)
- C++ 開(kāi)發(fā)之實(shí)現(xiàn)操作符重載的實(shí)例
- C++ 中placement new 操作符使用方法
- C++ operator關(guān)鍵字(重載操作符)的用法詳解
- C++ new、delete(new[]、delete[])操作符重載需要注意的問(wèn)題
- c++ 前自增/后自增操作符效率分析
相關(guān)文章
ShellExecute函數(shù)用法的實(shí)例代碼
ShellExecute函數(shù)用法的實(shí)例代碼,需要的朋友可以參考一下2013-03-03
詳解C++ 動(dòng)態(tài)內(nèi)存分配與命名空間
這篇文章主要介紹了詳解C++ 動(dòng)態(tài)內(nèi)存分配與命名空間,小編覺(jué)得挺不錯(cuò)的,現(xiàn)在分享給大家,也給大家做個(gè)參考。一起跟隨小編過(guò)來(lái)看看吧2018-08-08
C語(yǔ)言實(shí)現(xiàn)24位彩色圖像二值化
這篇文章主要為大家詳細(xì)介紹了C語(yǔ)言實(shí)現(xiàn)24位彩色圖像二值化,文中示例代碼介紹的非常詳細(xì),具有一定的參考價(jià)值,感興趣的小伙伴們可以參考一下2021-10-10
C++實(shí)現(xiàn)一個(gè)簡(jiǎn)易版的事件(Event)的示例代碼
之前在?windows系統(tǒng)中開(kāi)發(fā)應(yīng)用時(shí),?遇到需要進(jìn)行線程同步的時(shí)候幾乎都是使用的事件內(nèi)核對(duì)象?Event。本文為大家整理了C++實(shí)現(xiàn)一個(gè)簡(jiǎn)易版的事件(Event)的相關(guān)資料,需要的可以參考一下2022-11-11

