arduino中的char *声明是什么?

时间:2013-07-19 15:22:31

标签: char arduino

char *song;这样的声明是什么 *有什么作用?它是数组,指针还是别的什么?

3 个答案:

答案 0 :(得分:7)

*(星号)表示变量是指针。至于一个小例子:

int x = 0;
int *y = &x; //y is pointing to x
const char* myText = "Text";

然而,您可能有兴趣更多地了解what pointers are

答案 1 :(得分:3)

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'

等等

答案 2 :(得分:2)

是星号使它成为一个指针。似乎你已经足够其他答案,但如果你正在寻找一本好书:http://cm.bell-labs.com/cm/cs/cbook/

〜克里斯