Thread: Doubt

  1. #1
    Registered User
    Join Date
    May 2004
    Posts
    1

    Doubt

    Are char **n and char n[][] equal or different? If equal or different why?

  2. #2
    Registered User loopy's Avatar
    Join Date
    Mar 2002
    Posts
    172
    Quote Originally Posted by ansi_1999
    Are char **n and char n[][] equal or different? If equal or different why?
    Code:
    char **n;
    Is a pointer to a pointer of type char:

    Code:
    char n[][]
    Is a two dimetional array of type char, if the second was written:

    Code:
    char n[10][10];
    array 'n' would be an array in which each element contains 10 other elements.

    I hope thats correct.

  3. #3
    Registered User
    Join Date
    May 2004
    Posts
    127
    Quote Originally Posted by ansi_1999
    Are char **n and char n[][] equal or different? If equal or different why?
    They're different. "char **n;" is a valid declaration of a pointer to a pointer called n. "char n[][]" is an illegal declaration. Even if it were correct: "char n[size][size];", the two would still be different. Arrays and pointers are not the same beast even though arrays will almost always decay into a pointer to the first element when you use them.

  4. #4
    Registered User linuxdude's Avatar
    Join Date
    Mar 2003
    Location
    Louisiana
    Posts
    926
    Code:
    char n[][]" is an illegal declaration. Even if it were correct: "char n[size][size];",
    only the first [] needs to be filled in ex(this is legal)
    Code:
    char array[2][]={"blah","blah"};

  5. #5
    Registered User
    Join Date
    May 2004
    Posts
    127
    Quote Originally Posted by linuxdude
    Code:
    char n[][]" is an illegal declaration. Even if it were correct: "char n[size][size];",
    only the first [] needs to be filled in ex(this is legal)
    Code:
    char array[2][]={"blah","blah"};
    You're turned around. Only the first dimension can be omitted, and then only if the declaration isn't a definition or the definition includes an initialization list so that the compiler might be able to determine the size without one explicitly being given. Your example is not legal, but these are.
    Code:
    char array[][5]={"blah","blah"};
    Code:
    extern char array[][5];

  6. #6
    Registered User linuxdude's Avatar
    Join Date
    Mar 2003
    Location
    Louisiana
    Posts
    926
    I knew that. I wonder why I screwed that up. Thanx for the fix

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Doubt in pointer.
    By shwetha_siddu in forum C Programming
    Replies: 5
    Last Post: 03-21-2009, 01:28 AM
  2. doubt in c parser coding
    By akshara.sinha in forum C Programming
    Replies: 4
    Last Post: 12-23-2007, 01:49 PM
  3. Replies: 4
    Last Post: 12-10-2006, 07:08 PM
  4. Doubt abt Storage!
    By kalamram in forum C Programming
    Replies: 1
    Last Post: 04-21-2006, 05:30 AM
  5. Greatest C++ Doubt
    By vasanth in forum C++ Programming
    Replies: 15
    Last Post: 02-28-2002, 04:41 AM