What does the asterix after the char identifier which is apart of the variable name mean?
Ex. char *file = "something";
What does the asterix after the char identifier which is apart of the variable name mean?
Ex. char *file = "something";
It means you're declaring a pointer, in this case a pointer initialized to a string located in read-only memory.
dwk
Seek and ye shall find. quaere et invenies.
"Simplicity does not precede complexity, but follows it." -- Alan Perlis
"Testing can only prove the presence of bugs, not their absence." -- Edsger Dijkstra
"The only real mistake is the one from which we learn nothing." -- John Powell
Other boards: DaniWeb, TPS
Unofficial Wiki FAQ: cpwiki.sf.net
My website: http://dwks.theprogrammingsite.com/
Projects: codeform, xuni, atlantis, nort, etc.
In that context it makes file a pointer to char. But the asterisk isn't really a part of the variable name. The same pointer could be written,
which is the same asCode:char* file;
which is alsoCode:char * file;
A lot of people will tell you that the asterisk is just there to remind you that file is a pointer, which is true, until you decide to use the dereference operator to get the value stored in memory:Code:char *file;Code:*file = "something new";
Last edited by whiteflags; 05-04-2006 at 02:20 PM.
It's similar, but not the same as, an array.
Code:const char *progname = "program"; char progname2[] = "program";
dwk
Seek and ye shall find. quaere et invenies.
"Simplicity does not precede complexity, but follows it." -- Alan Perlis
"Testing can only prove the presence of bugs, not their absence." -- Edsger Dijkstra
"The only real mistake is the one from which we learn nothing." -- John Powell
Other boards: DaniWeb, TPS
Unofficial Wiki FAQ: cpwiki.sf.net
My website: http://dwks.theprogrammingsite.com/
Projects: codeform, xuni, atlantis, nort, etc.
To put it simply(ish), a pointer variable isn't a char, or int, or whatever it's pointing to - it just holds the memory address of whatever it's pointing to. (As an unsigned integer, I believe. Though that doesn't make much difference unless you want to alter it or put it into a printf statement.)