关于内存分配地址的一个有关问题求解
关于内存分配地址的一个问题求解
EMC 笔试题之一 关于内存分配地址的一个问题求解 我的答案是E 大家看看吧
If one compiled and ran following C Program in Windows or Linux, which of the statements below is(are) correct about the program's run-time memory allocation?
#include <stdio.h>
#include <stdlib.h>
int a = 1024;
void test(int c)
{
static int b[20];
int* p = (int*)malloc(c * sizeof(int));
}
int main(void)
{
test(a * 1024);
return 0;
}
A. Memory used by variable 'p' is allocated in a stack area.
B. Memory used by array variable 'b' is allocated in a stack area.
C. Memory used by variable 'c' is allocated in a heap area.
D. The memory address returned by malloc() is a virtual address, but the memory address of expression "&a"is not a virtual address
E. Memory to which is pointed by pointer 'p' is leaked. After the program termination, system loses control of that memory area.
------解决方案--------------------
E不对吧,程序结束之后,操作系统会回收应用程序所使用的所有资源,包括静态内存和动态内存,程序结束之后,这块内存会被其他程序使用。
------解决方案--------------------
偶认为是A
EMC 笔试题之一 关于内存分配地址的一个问题求解 我的答案是E 大家看看吧
If one compiled and ran following C Program in Windows or Linux, which of the statements below is(are) correct about the program's run-time memory allocation?
#include <stdio.h>
#include <stdlib.h>
int a = 1024;
void test(int c)
{
static int b[20];
int* p = (int*)malloc(c * sizeof(int));
}
int main(void)
{
test(a * 1024);
return 0;
}
A. Memory used by variable 'p' is allocated in a stack area.
B. Memory used by array variable 'b' is allocated in a stack area.
C. Memory used by variable 'c' is allocated in a heap area.
D. The memory address returned by malloc() is a virtual address, but the memory address of expression "&a"is not a virtual address
E. Memory to which is pointed by pointer 'p' is leaked. After the program termination, system loses control of that memory area.
malloc memory
------解决方案--------------------
E不对吧,程序结束之后,操作系统会回收应用程序所使用的所有资源,包括静态内存和动态内存,程序结束之后,这块内存会被其他程序使用。
------解决方案--------------------
偶认为是A