服务器之家:专注于服务器技术及软件下载分享
分类导航

PHP教程|ASP.NET教程|Java教程|ASP教程|编程技术|正则表达式|C/C++|IOS|C#|Swift|Android|VB|R语言|JavaScript|易语言|vb.net|

服务器之家 - 编程语言 - C/C++ - 基于C++输出指针自增(++)运算的示例分析

基于C++输出指针自增(++)运算的示例分析

2020-12-10 14:43C++教程网 C/C++

本篇文章是对C++中输出指针自增(++)运算的示例进行了详细的分析介绍,需要的朋友参考下

复制代码 代码如下:


#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
-------------------
请按任意键继续. . .

延伸 · 阅读

精彩推荐