0402月

c语言学习笔记~

▧ 2005.02.04

定义 int **a[3][4], 则变量占有的内存空间为:_____ 答案1:434=48 字节

如果是在64位机器上呢? 呵呵 地址八个字节

这里应该就是定义了一个指针变量吧。 2个字节。 晓梦也感觉应该是2个字节..虽然不知道为什么...

一程序包含下面的语句: #define MAX_INPUT 1000 char input[MAX_INPUT]; while(gets(input)!=NULL) { .   .   .  } 你认为这段代码(主要是循环结构)可能会出现什么问题?

define只作简单替换

我这为这段程序问题在于gets函数是从流中读取一行的信息,它在读取到newline或者EOF或者error的时候结束,而定义的那个数组没有提供能使gets结束的信息,所以也许while里的条件永远都不会为NULL

GETS(3)             Linux Programmer’s Manual             GETS(3)

gets(): reads a line from stdin into the buffer pointed  to        by  s  until either a terminating newline or EOF, which it        replaces with ‘\0’.  No check for buffer overrun  is  per        formed (see BUGS below).

BUGS        Never use gets().  Because it is impossible to tell  with        out knowing the data in advance how many characters gets()        will read, and because gets() will continue to store char        acters past the end of the buffer, it is extremely danger        ous to use.  It has been used to break computer  security.        Use fgets() instead.

       It  is  not advisable to mix calls to input functions from        the stdio library with low - level calls to read() for the        file  descriptor  associated  with  the  input stream; the        results will be undefined and very probably not  what  you        want.

这个解释的够清楚了!:)

关联记录 · 2 条评论

龙叔
路过….在小龙的K7-600上痛苦的翻阅SB的BLOG。。。。。。这到处乱翻原来也是体力活儿啊。。。。。。。
晓梦回复 #68

...你体力活还少干了啊?

来..马儿..驾!