您的位置:首页 > 编程语言 > C语言/C++

C语言几个有意思的问题

2013-12-12 11:44 225 查看
1、gets和fgets的区别

char *gets(char *s);

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 performed (see BUGS below).

char *fgets(char *s, int size, FILE *stream);

fgets() reads in at most one less than size characters from stream and stores them into the buffer pointed to by s. Reading stops after an EOF or a newline. If a newline is read, it is stored into the buffer. A '\0' is stored after the last character
in the buffer.



2、运行时改变程序名称

memset(argv[0],0,strlen(argv[0])); strncpy(argv[0],"NewName",7);然后ps可以发现程序名称改变了



3、print从右到左运算输出

#include <stdio.h>

int main(void)

{

int a = 10, b = 20, c = 30;

printf( "\n %d..%d..%d\n", a+b+c,(b=b*2),(c=c*3) );

}

140..40..90
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: