I was just wondering about character array offsets and
array names. If I declare:
char* a;
char* theString[]="Hello World";
a=theString;
a++;
Will a[0] now show 'e'?
This is a discussion on Array names and char*'s within the C++ Programming forums, part of the General Programming Boards category; I was just wondering about character array offsets and array names. If I declare: char* a; char* theString[]="Hello World"; a=theString; ...
I was just wondering about character array offsets and
array names. If I declare:
char* a;
char* theString[]="Hello World";
a=theString;
a++;
Will a[0] now show 'e'?
A minor correction:
The variable a is not an array so you really shouldn't be using the [] array indexing scheme. After the above code is run, a will point to the second element of theString which means that *a will equal 'e'.Code:char* a; char theString[]="Hello World"; // Notice no '*' after char a=theString; a++;
I used to be an adventurer like you... then I took an arrow to the knee.
Look at my program, in my case, it print's 'e':
Code:#include <stdio.h> int main(void) { char *ptrStr; char *str = "Hello World"; ptrStr = str; printf("%c\n",*(++ptrStr)); getchar(); return 0; }
Thanks. This means array names are much more powerful than I thought!