楼主:
cord (海派甜心)
2014-05-17 01:13:22开发平台(Platform): (Ex: VC++, GCC, Linux, ...)
dev-c
额外使用到的函数库(Library Used): (Ex: OpenGL, ...)
c语言
问题(Question):
*[36m程式码(Code):(请善用置底文网页, 记得排版) *[m
#include <stdio.h>
#include <stdlib.h>
#include <malloc.h>
int main(int argc, char *argv[]) {
int len = 0;
int * pArr = (int*)malloc(sizeof(int)*len);
pArr[0] = 987;
pArr[1] = 100;
pArr[2] = 200;
pArr[3] = 300;
pArr[4] = 400;
printf("%d %d %d %d %d",pArr[0],pArr[1],pArr[2],pArr[3],pArr[4]);
return 0;
}
预期的正确结果(Expected Output):
执行正确 但为什么len设为零
还是可以印出来 不会出错
执行结果
987 100 200 300 400
作者: tomnelson 2014-05-17 14:51:00
不强制转型compile时会有warning吧!? 但你pArr都宣告成pointer to int,电脑当然也用pointer to int的结构去操作pArr,会出什么错误?