0

我知道 a*与指针有关。我仍在尝试在脑海中解决这个问题(指针与引用。)

我正在阅读一本 C++ 书籍,其中有一个方法签名,如下所示:

void DrawBitmap(char *filename, int x, int y)

*在这种情况下是什么意思?它是接受指针还是对变量的引用?

感谢您的帮助......并忍受了一个公认的菜鸟问题。

4

3 回答 3

4

这意味着您正在向它传递一个指向字符的指针,这通常意味着指针指向字符数组中的第一个字符。使用指针 ( *),您可以进行算术运算,例如 (fileName + 1) 来获取第二个字符。当您使用引用 ( &) 时,您暗示接收函数应该对原始数据进行操作。如果没有引用,函数会传递一个副本,而不是原始的。

于 2012-04-14T20:11:15.833 回答
1

Others have directly answered your question already; some of the following links are well worth a read for information about pointers (and their syntactical relationship to arrays in C++), they're well worth studying and I would recommend taking a little time reading through them to get your head around the ideas:

http://www.c-faq.com/aryptr/

http://www.augustcouncil.com/~tgibson/tutorial/ptr.html

http://www.augustcouncil.com/~tgibson/tutorial/arr.html

http://www.eternallyconfuzzled.com/tuts/languages/jsw_tut_pointers.aspx

http://www.daweidesigns.com/cgi-bin/pointers.php

于 2012-04-14T20:19:14.927 回答
0

char *filename是指向要传递给DrawBitmap方法的字符的指针。有关详细信息,请参阅此链接

于 2012-04-14T20:11:40.003 回答