由买买提看人间百态

boards

本页内容为未名空间相应帖子的节选和存档,一周内的贴子最多显示50字,超过一周显示500字 访问原贴
JobHunting版 - c/c++ question
相关主题
问个c++的问题一个容易记忆的permutation算法
问个缺少逗号的数组赋值问题好记(但不是最优)的combination算法
c++ 程序一问one C++ question
请教C/C++小C++ object size一问
看看这道题One C++ question
Dennis Ritchie - Unix, C language designer - Diedone C++ question
amazon的那道题目发个题目给大家复习一下marco
Interview questions, BloombergWhy I can't compile this function successfully
相关话题的讨论汇总
话题: input话题: hello话题: std话题: word话题: int
进入JobHunting版参与讨论
1 (共1页)
c****l
发帖数: 1280
1
int main()
{
char *input[] ={"a","b","c",0};
for(int i =0; input[i];i++) {
std::cout << "hello word" << std::endl;
}
return 0;
}
how many "hello word"? why?
a******p
发帖数: 157
2
input 是指针数组,最后一个input[3]=0空指针,其余都指向某个位置
一共3个hello world.
d****j
发帖数: 293
3
这本书上的一个解释:
The C programming Language
By Brian W. Kernighan and Dennis M. Ritchie.
见附件

【在 c****l 的大作中提到】
: int main()
: {
: char *input[] ={"a","b","c",0};
: for(int i =0; input[i];i++) {
: std::cout << "hello word" << std::endl;
: }
: return 0;
: }
: how many "hello word"? why?

r*******y
发帖数: 1081
4
how to explain why I have 6 "hello world" if I change the
code a little bit as below:
int main()
{
char *input[] ={"a","b","c","0"}; // little change here
for(int i =0; input[i];i++) {
std::cout << "hello word" << std::endl;
}
return 0;
}

【在 c****l 的大作中提到】
: int main()
: {
: char *input[] ={"a","b","c",0};
: for(int i =0; input[i];i++) {
: std::cout << "hello word" << std::endl;
: }
: return 0;
: }
: how many "hello word"? why?

r*******e
发帖数: 7583
5
你这是内存越界了,出4个5个6个7个直到任意个都有可能

【在 r*******y 的大作中提到】
: how to explain why I have 6 "hello world" if I change the
: code a little bit as below:
: int main()
: {
: char *input[] ={"a","b","c","0"}; // little change here
: for(int i =0; input[i];i++) {
: std::cout << "hello word" << std::endl;
: }
: return 0;
: }

x*********g
发帖数: 69
6
答案有吗?
是不是4个hello world,然后出错:input[4]越界了
M7
发帖数: 219
7
运行一下不就知道了吗?
3 "hello word"

【在 c****l 的大作中提到】
: int main()
: {
: char *input[] ={"a","b","c",0};
: for(int i =0; input[i];i++) {
: std::cout << "hello word" << std::endl;
: }
: return 0;
: }
: how many "hello word"? why?

x*********g
发帖数: 69
8
运行了一下
3个hello world
input[3]=0x00 bad pointer。
问一下,
是不是char *input[]赋值,i位错误时,input[i]默认为0x00
r*******y
发帖数: 1081
9
thanks.

【在 r*******e 的大作中提到】
: 你这是内存越界了,出4个5个6个7个直到任意个都有可能
r*******y
发帖数: 1081
10
thanks.

【在 r*******e 的大作中提到】
: 你这是内存越界了,出4个5个6个7个直到任意个都有可能
c****l
发帖数: 1280
11
the real question is "why". thanks

【在 M7 的大作中提到】
: 运行一下不就知道了吗?
: 3 "hello word"

1 (共1页)
进入JobHunting版参与讨论
相关主题
Why I can't compile this function successfully看看这道题
C++: what is the output? How to interpret it?Dennis Ritchie - Unix, C language designer - Died
C++ Q42: (C22)amazon的那道题目
问个c++题Interview questions, Bloomberg
问个c++的问题一个容易记忆的permutation算法
问个缺少逗号的数组赋值问题好记(但不是最优)的combination算法
c++ 程序一问one C++ question
请教C/C++小C++ object size一问
相关话题的讨论汇总
话题: input话题: hello话题: std话题: word话题: int