-
int* vs int[]
Today I took a test at my university about C. The question was:
What is the difference between the pointer to the int value and the int array, i.e., int *p vs. int p[]?
My answer was that there is a diffence. You can change the value of the pointer (int*) and sizeof(array) return the whole size of the array not just size of the pointer. But when I use it as function arguments then they are both viewed as int*.
My teacher is saying that it is wrong and they are the same.
Who is right? Please take into consideration the whole question because maybe I interpreted it in a wrong way.
-
You are right, and given what you wrote, you should be able to easily construct a program to demonstrate it to your teacher just as you described.
Of course, if the question had been something like: "What is the difference between the syntax int *p vs. int p[] when used to declare a function parameter?" then indeed your teacher would be correct, but as it explicitly specified "the pointer to the int value and the int array", your teacher is unequivocally wrong according to the C standard.
-
Thank you very much for your help. You helped a lot :biggrin: