(学习笔记)栈数据结构中压(入)栈操作(C语言实现)

         在用C语言实现栈结构,实现压栈、进栈操作的时候,会碰到栈满的情况,此时需要增加栈的大小,在C语言的代码中将要用到realloc();这个函数,发现对这个函数认识模糊,查了各种资料,发现网上网友总结的内容都非常模糊,于是翻了一翻《the  C programming language》,在其附录中对realloc函数是这样描述的:
                    “void *realloc(void *p,size_t size);       realloc changes the size of the object pointed to by p to size. The contents will be unchanged up to the minimum of the old and new sizes.If the new size is larger, the new space is uninitialized .realloc  returns a pointer to the new space ,or ,NULL if the request cannot be satisfied ,in which case *p is unchanged."意思是”realloc函数改变p指针指向对象的大小,也就是指向的内存的大小,对象中的内容并不会被改变。如果让p指向更大的内存,新的内存不会被初始化。realloc返回一个指向新内存的指针,如果申请新内存失败,返回NULL指针,但是*p指针指向的内存不会被改变“
       在百度百科上搜到的解释是这样的:realloc原型是extern void *realloc(void *mem_address, unsigned int newsize);
       先判断当前的指针是否有足够的连续空间,如果有,扩大mem_address指向的地址,并且将

  • 0
    点赞
  • 3
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值