C Programming - Pointers - Discussion

Discussion Forum : Pointers - True / False Questions (Q.No. 4)
4.
Are the three declarations char **apple, char *apple[], and char apple[][] same?
True
False
Answer: Option
Explanation:
No answer description is available. Let's discuss.
Discussion:
43 comments Page 2 of 5.

Prabal said:   10 years ago
You can't increment an array as for:

apple[][] you can't do apple++.

*apple[] you can't do apple++.

**apple you can do apple++.

Simply array variable acts as a pointer but we can't modify it to point to another location in case of apple++ in apple array variable. We can do apple+1 but doing apple = apple+1 would give an error.

Patil said:   10 years ago
1. **a = *(*(a+0)+0) = a[][].

2. *a[] = *(*(a+0)+0), where a[] = *(a+0).

2.1 *a[] = **(a+0) or,

2.2 *a[] =*(*(a+0)+0).

Above 2.1 and 2.2 both are same are different.

3. Apple[][] = *(*(a+0)+0).

Shemonti said:   1 decade ago
But char *apple[] and char apple[][] both denote 2D array.like we can declare char *apple[]={"mango",
"grapes",
"jack fruit"};

And char apple[3][10]={
"mango",
"grapes",
"jack fruit"};

Both will give same result.

Iceberg said:   1 decade ago
@pranav
2D array of character is not string , string is 1D array.
char * is a string. or char str[] is a string.
2D array will be a para. where each line is a string, rem string can have white space.
For the ques above. their name or notation are different , but all of them are mostly used to indicate a 2d array. but they can be used for different pupose too. so they are different.

Pranav kumare said:   1 decade ago
All three can be used to initiate a 2D array of character i.e string.

But here **apple indicates that this is a pointer to a char pointer.

*apple[] indicates that this is an array of pointers.

apple[][] indicates that this is an 2D array of characters i.e string;

Ashwini said:   1 decade ago
char **apple - double pointer.
char *apple[] - array of pointers.
char apple[][] - 2D array.
char (*apple)[5] - pointer to an array of 5 characters.

BDS said:   1 decade ago
char **apple ------>Its a double Pointer.

char *apple[] -------->Array of Pointers.

char apple[][] ---------->2D Array.

Manjunath said:   1 decade ago
See both are proper.

char **apple -----------> This is Double Pointer
char *apple[] -----------> This is Array Pointer
char apple[][] -----------> This is 2D Array

As well as,
**a
or
*a[]
or
**a[]
are the same statement.

It works according to the way you use.

Ex: char *p and char p[] both are same and both indicates string.
Similarly all above statements are same.

Anil said:   1 decade ago
char **apple -----------> This is Double Pointer
char *apple[] -----------> This is Array Pointer
char apple[][] -----------> This is 2D Array

Hariom said:   1 decade ago
char **apple is pointer of pointer.


Post your comments here:

Your comments will be displayed after verification.