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?
Discussion:
43 comments Page 1 of 5.
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.
"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.
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.
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.
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.
Nanthagopal said:
6 years ago
For all the three cases memory allocation itself is different, doesn't anyone notice this.
apple[][] is fully allocated continuous memory locations.
*apple[] - the first dimension is continuously memory allocated whereas the second dimension is discrete pointers pointing random memory addresses.
**apple - here all the memory locations are randomly allocated.
apple[][] is fully allocated continuous memory locations.
*apple[] - the first dimension is continuously memory allocated whereas the second dimension is discrete pointers pointing random memory addresses.
**apple - here all the memory locations are randomly allocated.
(2)
Rupinderjit said:
1 decade ago
#1:t's pointer to pointer to variable,that is,it points to another pointer which further points to variable apple's address.
#2:It's array of pointers(uninitialized),usually used to hold number of strings,that is,it is pointer to array of strings.
#3:It is simply array declaration and variable name array is pointer to first element of itself.
#2:It's array of pointers(uninitialized),usually used to hold number of strings,that is,it is pointer to array of strings.
#3:It is simply array declaration and variable name array is pointer to first element of itself.
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.
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.
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;
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;
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).
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).
Anil said:
1 decade ago
char **apple -----------> This is Double Pointer
char *apple[] -----------> This is Array Pointer
char apple[][] -----------> This is 2D Array
char *apple[] -----------> This is Array Pointer
char apple[][] -----------> This is 2D Array
Kodi said:
3 years ago
Yes, exactly it is the correct explanation.
char **apple - It is a double pointer,
char *apple[] -It is an array of pointers,
char apple[][]-It id 2-d array.
char **apple - It is a double pointer,
char *apple[] -It is an array of pointers,
char apple[][]-It id 2-d array.
Post your comments here:
Quick links
Quantitative Aptitude
Verbal (English)
Reasoning
Programming
Interview
Placement Papers