* what ?

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 ?...

  1. #1
    Unregistered
    Guest

    * what ?

    what's the difference between


    char *s;

    and

    char *r[];


    and can you convert the second to the first ?

  2. #2
    S­énior Member
    Join Date
    Jan 2002
    Posts
    982
    >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 -

    Code:
    #include <iostream>
    
    int main()
    {
    	char * s;
    	char * t[3]={"tt","ss","rr"};
    	s=(char*)t;
    	std::cout << *(char **)s << '\n';
    	return 0;
    }
    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 -

    s=t[0];
    std::cout << s;
    Last edited by Sorensen; 02-28-2002 at 05:09 PM.

Popular pages Recent additions subscribe to a feed

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21