函数和指针的运用
来源:互联网 发布:北航 矩阵 答案 编辑:程序博客网 时间:2024/06/05 16:43
#include <stdlib.h>int *f1(void){ int x = 10; return &x;}int *f2(void){ int *ptr; *ptr = 10; return ptr;}int *f3(void){ int *ptr; ptr = malloc(sizeof *ptr); return ptr;}f1和f2运用时有错误的。
Function f1
returns the address of a local variable. Since the variable’s lifetime ends after the function returns, any use of the return value produces undefined behavior.
Function f2
produces undefined behavior because it dereferences and returns an uninitialized pointer. (It has not been assigned to point to anything, and its initial value is indeterminate.)
Function f3
has no errors (although its caller should make sure the return value is not NULL before using it, and callfree
when the memory is no longer needed).
- 函数和指针的运用
- 函数指针的运用
- 函数指针及其的运用
- C++函数指针的运用
- 函数指针及其的运用
- C语言指针的函数运用和数组
- 8.6函数调用与数组和指针的运用
- 指向函数的指针_简单运用
- C++中函数指针的运用
- 指针数组函数的综合运用
- 数值积分(函数指针的运用)
- 指针及scanf函数的运用
- 关于嵌入式编程函数指针的运用
- 运用函数指针和STL的Map实现关键字key与成员函数的映射
- 函数指针及其运用
- C中内存和指针的运用
- 指针和标记法的运用
- c指针和malloc的运用注意
- 堆和栈的区别
- 软件分享 kemulator lite
- 创新工场2011年校园招聘笔试题
- HDU-1010-Tempter of the Bone
- POJ 1275 差分约束
- 函数和指针的运用
- JScript.chm
- 构造函数和析构函数
- Java反射(Reflection)与内省(Introspector)
- C# 操作 Access2010
- androidlistview
- 如何求两个向交矩形的交集的面积?
- 算法经典书籍
- C语言程序设计(常用函数说明)