zoukankan      html  css  js  c++  java
  • point(指针)

     1 /*************************************************************************
     2     > File Name: change.cpp
     3     > Author:sunshunzhong
     4     > Mail:13115543132@163.com 
     5     > Created Time: 2016年05月23日 星期一 15时39分33秒
     6  ************************************************************************/
     7 
     8 #include<iostream>
     9 using namespace std;
    10 int main()
    11 {
    12     int a=5,b=6;
    13     int *p1,*p2,p;
    14     p1=&a;  
    15     p2=&b;
    17     cout<<"p2 "<<*p2<<endl;
    19     b=*p1; 
    20     cout<<"b:"<<b<<endl;
    21     a=*p2;
    22     cout<<"a:"<<a<<endl;
    23     cout<<"p1:"<<*p1<<endl;
    24     cout<<"p2:"<<*p2<<endl;
    25     cout<<" a , b "<<a<<" "<<b<<endl;
    26     return 0;
    27 
    28 }

    p1 只是指向a的地址,,p2 指向b 的地址, b=*p1,p2指向b的地址里面,b的值发生了改变,最终a 的又变成5

     1 /*************************************************************************
     2     > File Name: change.cpp
     3     > Author:sunshunzhong
     4     > Mail:13115543132@163.com 
     5     > Created Time: 2016年05月23日 星期一 15时39分33秒
     6  ************************************************************************/
     7 
     8 #include<iostream>
     9 using namespace std;
    10 int main()
    11 {
    12     int a=5,b=6;
    13     int *p1,*p2,p;
    14     p1=&a;  // p1 存放 a 的值
    15     p2=&b;
    16       // b 的值赋给 a
    17     cout<<"p2 "<<*p2<<endl;
    18     p=*p2; // p=6
    19     b=*p1; // b=5 p2=&b; *p2=5
    20     cout<<"b:"<<b<<endl;
    21     a=p;
    22     cout<<"a:"<<a<<endl;
    23     cout<<"p1:"<<*p1<<endl;
    24     cout<<"p2:"<<*p2<<endl;
    25     cout<<" a , b "<<a<<" "<<b<<endl;
    26     return 0;
    27 
    28 }

  • 相关阅读:
    KMP算法中next数组的构建
    vijos 1243 生产产品
    codeforces 557E Ann and Half-Palindrome
    codeforces 557D Vitaly and Cycle
    vijos 1054 牛场围栏 【想法题】
    oracle数据库基本操作
    一位90后程序员的自述:如何从年薪3w到30w
    Oracle 树操作(select…start with…connect by…prior)
    oracle中的条件语句
    重置按钮_reset
  • 原文地址:https://www.cnblogs.com/-210843013/p/5520672.html
Copyright © 2011-2022 走看看