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