Welcome, Guest. Please login or register.

Author Topic: C string syntax incoherent ? ...  (Read 2394 times)

Description:

0 Members and 1 Guest are viewing this topic.

Offline Castellen

Re: Stupid bloody C string question...
« on: December 26, 2004, 09:00:27 PM »
Sounds like you're just getting confused by pointers??

The pointer strg only holds a single memory address, the address of the beginning of the string.

While if you had a char string called strg, the string array called strg would hold "C rules!!\0"

Here's one way to demonstrate the use of a pointer:

char *strg = "C rules!!!";   // That's saying put "C rules!!!\0 somewhere in memory, and give strg the address where the "C" is living.

printf("The data at address %d is: %s", strg, *strg);

Should print out something like:
The data at address 5816491 is: C rules!!!


A good way to remember it is * = the data at the address specified by the pointer.
& gets the address of a variable.
 

I think that's right.  Feel free to correct/abuse :-)
It's so confusing to begin with, I still have trouble with pointers!