assignment from incompatible pointer type

This is a discussion on assignment from incompatible pointer type within the C Programming forums, part of the General Programming Boards category; I assume that char *myArray[1] = "Hello!" ; char **ptr; *ptr = &myArray[0] is not compatible because one is an ...

  1. #1
    Registered User
    Join Date
    May 2010
    Posts
    178

    assignment from incompatible pointer type

    I assume that char *myArray[1] = "Hello!" ; char **ptr; *ptr = &myArray[0] is not compatible because one is an array and the other an integeral type?

  2. #2
    Registered User
    Join Date
    Oct 2006
    Posts
    250
    Wrong.

    What type is *ptr?
    What type is &myArray[0]?

  3. #3
    Registered User
    Join Date
    Jul 2010
    Posts
    33
    I think you meant *ptr = myArray[0]; but that's uninitialised memory according to your example, you want *ptr = myArray[1];

    char *myArray[] is an array of pointers to characters, so each index is a pointer to a character(s).

    Note, myArray ( and hence &myArray[0] ) is wrong because that's an array of pointers to character(s) and hence the name points to the address of a pointer and not the first character.
    Last edited by CSaw; 07-18-2010 at 04:24 PM.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. passing argument from incompatible pointer type
    By bhdavis1978 in forum C Programming
    Replies: 5
    Last Post: 03-17-2010, 12:42 PM
  2. incompatible pointer type?
    By kezman in forum C Programming
    Replies: 3
    Last Post: 04-22-2009, 04:42 PM
  3. pointers, structures, and malloc
    By lugnut in forum C Programming
    Replies: 24
    Last Post: 10-09-2008, 04:52 PM
  4. Please Help - Problem with Compilers
    By toonlover in forum C++ Programming
    Replies: 5
    Last Post: 07-23-2005, 10:03 AM
  5. Could somebody please help me with this C program
    By brett73 in forum C Programming
    Replies: 6
    Last Post: 11-25-2004, 01:19 AM

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