本文介绍了关于“定义”的问题和“malloc”的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧! 问题描述 29岁程序员,3月因学历无情被辞! CSS白色: 奇怪的是,我找到了定义无法使用malloc。我的 编译器会一起说解析错误。 有谁可以告诉我原因? ----- -------------------- #define MAX 10000 ....... int main(void){ ..... char * temp =(char *)malloc(MAX * sizeof(char)); ..... 系统(暂停); 返回0; } 遵守时,错误。 寻找解释。CSS white here:Simply strange, I found "define" can not work with "malloc". Together mycomplier will say "parse error".Could anyone tell me why?-------------------------#define MAX 10000.......int main(void){.....char * temp=(char *)malloc(MAX*sizeof(char));.....system("pause");return 0;}when complying, wrong.look for explanation.推荐答案 什么?what? 你错了you are mistaken 将来请发一个* * * * * * * *(((((((((((((((((((((( $ b计划。不要把......放在一起。在小程序中。 这个温和编辑的代码版本为我编译 #include< stdlib.h> #define MAX 10000 int main(无效) { char * temp = (char *)malloc(MAX * sizeof(char)); // system(" pause"); 返回0; }in future please post a *comple* *compilable* (well as close as youcan!)program. Don''t put "...." in small programs.This mildly edited version of your code compiles for me#include <stdlib.h>#define MAX 10000int main(void){char *temp = (char*)malloc (MAX * sizeof(char));// system("pause");return 0;} 不要施放malloc。根据定义,char的sizeof为1,所以写上面的 char * temp = malloc(MAX); 我也被你的布局所欺骗因为我比你更喜欢空白 使用。don''t cast malloc. sizeof of char is 1 by definition so write the abovechar * temp = malloc (MAX);I also fooled with your layout as I prefer more whitespace than youuse. 非标准non-standard 我怀疑你省略了包括stlib.h - Nick KeighleyI suspect you ommitted to include stlib.h--Nick Keighley 这篇关于关于“定义”的问题和“malloc”的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持! 上岸,阿里云!
08-26 12:17
查看更多