欢迎来到入门教程网!

C语言

当前位置:主页 > 软件编程 > C语言 >

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

来源:本站原创|时间:2020-01-10|栏目: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
-------------------
请按任意键继续. . .

上一篇:用32位int型变量表示单引号括起来的四个字符的深入探讨

栏    目:C语言

下一篇:基于C++ list中erase与remove函数的使用详解

本文标题:基于C++输出指针自增(++)运算的示例分析

本文地址:https://www.xiuzhanwang.com/a1/Cyuyan/4473.html

网页制作CMS教程网络编程软件编程脚本语言数据库服务器

如果侵犯了您的权利,请与我们联系,我们将在24小时内进行处理、任何非本站因素导致的法律后果,本站均不负任何责任。

联系QQ:835971066 | 邮箱:835971066#qq.com(#换成@)

Copyright © 2002-2020 脚本教程网 版权所有