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

软件发布|下载排行|最新软件

当前位置:首页IT学院IT技术

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

  2021-03-18 我要评论
想了解基于C++输出指针自增(++)运算的示例分析的相关内容吗,在本文为您仔细讲解C++输出指针自增(++)运算的相关知识和一些Code实例,欢迎阅读和指正,我们先划重点:输出,指针自增(++)运算,下面大家一起来学习吧。
复制代码 代码如下:

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

猜您喜欢

Copyright 2022 版权所有 软件发布 访问手机版

声明:所有软件和文章来自软件开发商或者作者 如有异议 请与本站联系 联系我们