zoukankan      html  css  js  c++  java
  • 浅拷贝和深拷贝问题

    #include <stdio.h>
    int main(int argc, char *argv[])
    {
        int x = 2;
        int y = x;
        
        int* p1 = &x;
        int* p2 = p1;
        printf("只拷贝值,不拷贝地址
    ");
        printf("深拷贝:x  = %p,value = %d
    ",&x,x);
        printf("深拷贝:y  = %p,value = %d
    ",&y,y);
        printf("只拷贝地址,不拷贝值
    ");
        printf("浅拷贝:p1 = %p,value = %d
    ",p1,*p1);
        printf("浅拷贝:p2 = %p,value = %d
    ",p2,*p2);
        return 0;
    }
    
    /*
    ---------- 运行c ----------
    只拷贝值,不拷贝地址
    深拷贝:x  = 0060FEF4,value = 2
    深拷贝:y  = 0060FEF0,value = 2
    只拷贝地址,不拷贝值
    浅拷贝:p1 = 0060FEF4,value = 2
    浅拷贝:p2 = 0060FEF4,value = 2
    
    输出完成 (耗时 0 秒) - 正常终止
    */
  • 相关阅读:
    hdu 2222 Keywords Search
    Meet and Greet
    hdu 4673
    hdu 4768
    hdu 4747 Mex
    uva 1513 Movie collection
    uva 12299 RMQ with Shifts
    uva 11732 strcmp() Anyone?
    uva 1401
    hdu 1251 统计难题
  • 原文地址:https://www.cnblogs.com/axuanup/p/12629441.html
Copyright © 2011-2022 走看看