zoukankan      html  css  js  c++  java
  • 堆和栈的一点知识

    堆和栈

    1、堆的增长方向是递增;
    2、栈的增长方向是递减。
    实验代码:

    printf("栈操作:
    ");
        int num1 = 10;
        int num2 = 11;
        printf("num1:%d
    ", num1);
        printf("num2:%d
    ", num2);
        printf("&num1:%d
    ", &num1);
        printf("&num2:%d
    ", &num2);//栈操作
        printf("堆操作:
    ");
        int *num3;
        int *num4;
        num3 = new int;
        num4 = new int;
        *num3 = 12;
        *num4 = 13;
        printf("*num3:%d
    ", *num3);
        printf("*num4:%d
    ", *num4);
        printf("num3:%d
    ", num3);
        printf("num4:%d
    ", num4);
        printf("&num3:%d
    ", &num3);
        printf("&num4:%d
    ", &num4);
        delete num3;
        delete num4;

    实验的结果如下:
    这里写图片描述
    在结果中:
    &num1、&num2、&num3、&num4四个地址是在栈中的,num3、num4两个地址是在堆中的。

    上善若水,为而不争。
  • 相关阅读:
    Connected Graph
    Gerald and Giant Chess
    [NOI2009]诗人小G
    四边形不等式小结
    [NOI2007]货币兑换
    Cats Transport
    Cut the Sequence
    Fence
    The Battle of Chibi
    [Usaco2005 Dec]Cleaning Shifts
  • 原文地址:https://www.cnblogs.com/Bearoom/p/11721820.html
Copyright © 2011-2022 走看看