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.
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)
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.
Susil said:
1 decade ago
Ya pooja and Mrutyunjay are correct.
Hariom said:
1 decade ago
char **apple is pointer of pointer.
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
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.
BDS said:
1 decade ago
char **apple ------>Its a double Pointer.
char *apple[] -------->Array of Pointers.
char apple[][] ---------->2D Array.
char *apple[] -------->Array of Pointers.
char apple[][] ---------->2D Array.
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.
char *apple[] - array of pointers.
char apple[][] - 2D array.
char (*apple)[5] - pointer to an array of 5 characters.
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;
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.
Post your comments here:
Quick links
Quantitative Aptitude
Verbal (English)
Reasoning
Programming
Interview
Placement Papers