electric
2012-08-30 08:05:05 UTC
It flows from the following question I had posted week back and which Contributor Henni answered:
http://answers.yahoo.com/question/index;_ylt=Amz6Je7QyeK5fyTuVqE3bgfty6IX;_ylv=3?qid=20120731063310AAZtM5j
I have divided my question into bits for clarity.It will be really nice & helpful of you if you can answer them in the same numbered order given the fact that I am not that good in programming yet.If you are too busy,I'll extend the duration of this question & wait till you get the time to answer.(My email is sheerfish@yahoo.com).THANKS.
So here's my question.
1)Going by Henni's answer to my older question linked above,if we declare a pointer to an integer array as "int (*ptr)[]" then string being a character array, why don't we declare a string pointer as "char (*ptr)[]"?Since this itself leads to "sub-questions", I have posted those in a different (short) question
http://answers.yahoo.com/question/index?qid=20120830080202AA2VbAC
2)IMPORTANT: If "int *(*ptr)[]" is a pointer to an array of integer pointers , what is **ptr[] then?Shouldn't it follow from Henni's definitions of "int (*ptr)[]" and "int *ptr[]" in the topmost linked question that "int **ptr[]" should be a "pointer to an array of integer pointers" and "int *(*ptr)[]" should be "a pointer to a pointer to an integer array"?Especially,HOW WOULD YOU WRITE A "POINTER TO A POINTER TO AN INTEGER ARRAY" THEN?Please give the reasons for your answer to this.
3)IMPORTANT:How do we declare an array of pointers to integer arrays(Is it as similar as "char *argv[]" being used to declare an array of pointers to character arrays(ie strings))?(Look at it in the context of how we declare an array of pointers to character arrays(strings) in "char *argv[]".If "char *argv[]" can mean an array of pointers to arrays of characters(strings),WHY CAN'T "int *ptr[]" MEAN "AN ARRAY OF POINTERS TO INTEGER ARRAYS" INSTEAD OF "AN ARRAY OF INTEGER POINTERS"?To repeat the main question, how do we declare an array of pointers to integer arrays, ie an array of pointers to a 2D integer array"?
4)If an array of pointers to characters is the same as an array of pointers to strings(from the case of "char *argv[]"),thereby meaning a pointer to a character is the same as a pointer to an array of character(string) (we declare it "char *ptr" for both character and string) then does it also mean that array of pointers to integers (ie. "int *ptr[]") is same as array of pointers to integer arrays, THEREBY meaning a pointer to an integer is the same as a pointer to an integer array? But that's clearly not so as we have different ways to declare an integer pointer and a pointer to an integer arrray("int *ptr" and "int (*ptr)[]" respectively)!!(Again refer to Henni's answer in the topmost linked question).And on the reverse, if declaration of pointer to an integer is different from declaration of pointer to an integer array,meaning an array of integer pointers can't point to integer arrays,then how come an array of character pointers point to character arrays(or strings) in "char *argv[]"??AAAGHH, GOD HELP ME!!
5)Now let me ask this rigorosly--Is the declaration of an array of pointers to strings same as declaration of an array of pointers to characters?Suppose I want to declare an array of pointers to strings and an array of pointers to characters.Here I define "array of pointers to strings" as "array of pointers to arrays of characters(.ie strings are arrays of characters after all) and I define "array of pointers to characters" as "array of pointers to single characters" as different from "arrays of characters or strings".So will the declaration for both be same as following?
char *ptr[];
Though I feel it's so , I want to confirm from you.I feel so because in a C main function, we write "int main(int argc,char *argv[])" and we say argv is an array of pointers to strings.If that's so please explain the following as it's directly related to the above:
a)Assuming an array of pointers to strings is same as array of pointers to strings, does it mean that the compiler determine whether the pointer wants to point to a single character or a string depending on context? Consider the following :
--If I pass an array element from "array