Thread: * what ?

  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