*p++,(*p)++,*++p,++*p区别

// ConsoleApplication1.cpp : 定义控制台应用程序的入口点。
//

#include "stdafx.h"
#include <iostream>
#include <string>
using namespace std;

int _tmain(int argc, _TCHAR* argv[])
{
    int a[5] = { 11, 22, 33, 44, 55 };
    int *p = a;
    //*p++ : 先返回指针所指的值,然后指针加1 
    cout << *p++ << endl;  //打印结果: 11
    cout << *p++ << endl;  //打印结果: 22
    cout <<a[0] << endl;  //打印结果: 11
    cout << "" << endl;  

    int b[5] = { 11, 22, 33, 44, 55 };
    int *r = b;
    // (*r)++ : 先返回指针所指的值,然后值加1
    cout << (*r)++ << endl; //打印结果:11
    cout << (*r)++ << endl; //打印结果:12
    cout << b[0] << endl;   //打印结果:13
    cout << "" << endl;

    int c[5] = { 11, 22, 33, 44, 55 };
    int *h = c;
    //*++h : 先将指针自加1,然后返回指针指向的值
    cout << *++h << endl; //打印结果:22
    cout << *++h << endl; //打印结果:33
    cout << c[0] << endl;   //打印结果:11
    cout << "" << endl;

    int d[5] = { 11, 22, 33, 44, 55 };
    int *k = d;
    //++*k :将指针指向的值,加1后返回
    cout << ++*k << endl; //打印结果:12
    cout << ++*k << endl; //打印结果:13
    cout << d[0] << endl;   //打印结果:13
    cout << "" << endl;

    system("pause");
    return 0;
}



FR:海涛高软(hunk Xu) QQ技术交流群:386476712

评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值