刚开始学C语言时遇到一个问题,如下代码:
以下是引用片段: #include int main() ...{ char a,b; printf("Please input the first character:"); scanf("%c", &a); printf("Please input the second character:"); scanf("%c", &b); printf("The two characters are %c, %c", a, b); return 0; } |
程序运行结果如下:

而下面这段程序却可以正常运行:
以下是引用片段: #include int main() ...{ char a; int b; printf("Please input the first character:"); scanf("%c", &a); printf("Please input the second integer:"); scanf("%d", &b); printf("The two characters are %c, %d", a, b); return 0; } |
运行结果如下:

当时对这个问题很困惑,时间一长就慢慢淡忘了。
昨天一个同学问到一个C++运算符重载的问题,如下代码,其中的while循环起什么作用,好像注释掉后程序运行没什么差别:
以下是引用片段: iostream& operator >> (iostream& is, b& s) ...{ char temp[b::MAX] = ...{0}; is.get(); is.get(temp, b::MAX); if(strlen(temp)>0) ...{ strncpy(b.str, temp, b::MAX); } while(is && is.get()!=' ') ...{ continue; } return is; } |
[1] [2] 下一页 |