【发布时间】:2013-07-19 15:22:30
【问题描述】:
什么是像char *song; 这样的声明
* 有什么作用?是数组、指针还是别的什么?
【问题讨论】:
什么是像char *song; 这样的声明
* 有什么作用?是数组、指针还是别的什么?
【问题讨论】:
*(星号)表示该变量是一个指针。举个小例子:
int x = 0;
int *y = &x; //y is pointing to x
const char* myText = "Text";
不过,您可能有兴趣了解更多关于 what pointers are 的信息。
【讨论】:
char *song = "smb:d=4,o=5,b=100:16e6,16e6,32p,8e6,16c6,8e6,8g6,8p,8g,8p,8c6,16p,8g,16p,8e,16p,8a,8b,16a#,8a,16g.,16e6,16g6,8a6,16f6,8g6,8e6,16c6,16d6,8b,16p,8c6,16p,8g,16p,8e,16p,8a,8b,16a#,8a,16g.,16e6,16g6,8a6,16f6,8g6,8e6,16c6,16d6,8b,8p,16g6,16f#6,16f6,16d#6,16p,16e6,16p,16g#,16a,16c6,16p,16a,16c6,16d6,8p,16g6,16f#6,16f6,16d#6,16p,16e6,16p,16c7,16p,16c7,16c7,p,16g6,16f#6,16f6,16d#6,16p,16e6,16p,16g#,16a,16c6,16p,16a,16c6,16d6,8p,16d#6,8p,16d6,8p,16c6" 所以我不知道它是一个数组还是什么
H2CO3 是对的,你应该阅读 c 和指针。
char *song = "smb:d=4,o=5,b=......."
是否和下面的代码做同样的事情
char song[] = "smb:d=4,o=5,b=......."
在这两种情况下,song 都是指向字符串数组的指针。 C++ 有一个字符串对象,但纯 C 使用 c_strings。 c_string 只是一个 char 数组。你有一个看起来像 c_string 的东西。
*song //the same as "song[0]" will equal 's'
*(song+1) //the same as "song[1]" will equal 'm'
*(song+2) //the same as "song[2]" will equal 'b'
等等
【讨论】: