zoukankan      html  css  js  c++  java
  • C/C++指针学习的两个经典实例

    2008年03月05日 15:43:26
    指针学习不好关键是概念不清造成的,说的简单点就是书没有认真看,指针的学习犹如人在学习饶口令不多看多学多练是不行的,下面是两个很经典的例子,很多书上都有,对于学习的重点在于理解*指针运算符的作用,假设定义了一个指针变量x,*x所表示的其实就是变量a本身,x表示的是变量a在内存中的地址,如果想明白可以输出观察cout<<*x"|"x;,当定义了int *x;后对x=&a的理解的问题。仔细阅读和联系下面的两个例子我想指针问题就不是难点了!


     C 代码 
     

     
    #include <stdio.h> 
     
    main() 
    { 
    int a,b; 
    int *point_1,*point_2,*temp_point; 
    scanf("%d,%d",&a,&b); 
    point_1=&a; 
    point_2=&b; 
    if (a<b) 
    { 
        temp_point=point_1; 
        point_1=point_2; 
        point_2=temp_point; 
        
    } 
    printf("%d,%d",*point_1,*point_2); 
    } 
     



     C 代码 
     

     
    #include <stdio.h> 
     
    main() 
    { 
    int a,b; 
    int *point_1,*point_2; 
    scanf("%d,%d",&a,&b); 
    point_1 = &a; 
    point_2 = &b; 
    compositor(point_1,point_2); 
    printf("%d,%d",a,b); 
    } 
     
    static compositor(p1,p2) 
    int *p1,*p2; 
    { 
    int temp; 
        if (*p1<*p2) 
        { 
            temp = *p1; 
            *p1 = *p2; 
            *p2 = temp; 
        } 
    } 
     




    Trackback: http://tb.donews.net/TrackBack.aspx?PostId=313359

     

    Trackback: http://tb.blog.csdn.net/TrackBack.aspx?PostId=2150640


  • 相关阅读:
    pytest之断言
    python之self
    python标准数据结构类型
    pytest之fixture
    python之继承和多态
    安卓UI自动化,pytest+UIautomator2+allure+jenkins
    airtest
    Python中单下划线开头的特性
    系统默认分配的共享内存太小,导致zabbix_server无法启动
    运行yum报错Error: Cannot retrieve metalink for repository: epel. Please verify its path and try again
  • 原文地址:https://www.cnblogs.com/feisky/p/1586591.html
Copyright © 2011-2022 走看看