what's the difference between
char *s;
and
char *r[];
and can you convert the second to the first ?
This is a discussion on * what ? within the C++ Programming forums, part of the General Programming Boards category; what's the difference between char *s; and char *r[]; and can you convert the second to the first ?...
what's the difference between
char *s;
and
char *r[];
and can you convert the second to the first ?
>char *s;
Pointer to character.
>char *r[];
Array of pointers to char
>and can you convert the second to the first ?
Yes, you can convert anything to anything using casts. Whether the result is meaningful (or readable) is another matter. See below -
If you wanted you could 'convert' an element of an array of pointers to a pointer by assigning one of the elements to a pointer -Code:#include <iostream> int main() { char * s; char * t[3]={"tt","ss","rr"}; s=(char*)t; std::cout << *(char **)s << '\n'; return 0; }
s=t[0];
std::cout << s;
Last edited by Sorensen; 02-28-2002 at 04:09 PM.