欢迎来到代码驿站!

C代码

当前位置:首页 > 软件编程 > C代码

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

时间:2020-10-03 10:15:14|栏目: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
-------------------
请按任意键继续. . .

上一篇:解析在WTL下使用双缓冲的实现方法

栏    目:C代码

下一篇:json error: Use of overloaded operator [] is ambiguous错误的解决方法

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

本文地址:http://www.codeinn.net/misctech/6387.html

推荐教程

广告投放 | 联系我们 | 版权申明

重要申明:本站所有的文章、图片、评论等,均由网友发表或上传并维护或收集自网络,属个人行为,与本站立场无关。

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

联系QQ:914707363 | 邮箱:codeinn#126.com(#换成@)

Copyright © 2020 代码驿站 版权所有