一點體會!

please read the following codes:

  extern char filename[128];
  static char path[128];
 
  void test(int num)
{
  char a[]="hello";
  char *p="world";
  static char *q=NULL;
  if(q!=NULL)
    q=(char *)malloc(100);
}

1)Memory of array "filename" is in ( )
A. Static stroage area
B. Heap
C. Stack
D. All of above are wrong.

2)Memory of array "path" is in ( )
A. Static stroage area
B. Heap
C. Stack
D. All of above are wrong.

3)Memory of variable "num" is in ( )
A. Static stroage area
B. Heap
C. Stack
D. All of above are wrong.

4)Memory of array "a" is in ( )
A. Static stroage area
B. Heap
C. Stack
D. All of above are wrong.

5)Memory of "p" is in ( )
A. Static stroage area
B. Heap
C. Stack
D. All of above are wrong.

6)Memory that "p" points to is in ( )
A. Static stroage area
B. Heap
C. Stack
D. All of above are wrong.

7)Memory of "q" is in ( )
A. Static stroage area
B. Heap
C. Stack
D. All of above are wrong.

8)Memory that "q" points to is in ( )
A. Static stroage area
B. Heap
C. Stack
D. All of above are wrong.
 变量分为:
1。auto自动型:此类变量存放于内存的动态存储区。
2。static静态型:此类变量存放于内存的静态存储区。
3。extern外部参照型:此类变量存放于内存的静态存储区。
4。register寄存器型:此类变量存放于CPU中的寄存器。

动态存储区分成堆(heap)和栈(stack)
1.堆:new 和malloc等类似方法生成的
2.栈:基本上除去第一种以外的都是。

由static 、extern 声明的变量以及全局变量都放在静态存储区
形参、局部变量放在栈中
由用户通过(malloc、new)申请的动态放在堆中
char *p="world";//指针p指向常量,常量位于静态存储区 6.a
static char *q=NULL; //q声明为static所以它位于静态存储区 7.a
if(q!=NULL)          //由于指针指向空,既不指向任何内存区
q=(char *)malloc(100);//这个语句没有执行 8.d

我的答案是1.a 2.a 3.c 4.c 5.c 6.a 7.a 8.d

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值