what is the main difference between arrays and pointers in c?

India
December 5, 2006 1:36am CST
what is the main difference between arrays and pointers in c language?
1 person likes this
2 responses
@dholey (1383)
• India
11 Jan 07
it is a nice question, i will try to explain it, in c , array name stands for the base addres of that array, that is , if you mention only the array name you will get the address of very first element (zeroth element), so it seems similar, but arrays are created with numbers of bytes (sum of the bytes required by members) for example if you create array of 5 int (int ar[5]) then the array will be created using 10 bytes, and pointers are special variables which deals with addresses, i.e. the value of pointer variable will be the address of some other variable, so in this case if you use array name or pointer name they seems similar as both will give addresses, but pointer is created using 2 bytes only (as memory address can be stored in two bytes) poinetr is a variable so the value of pointer can be changed , i.e the address stored in pointer can be changed where in array it always gives the base address , it can not be changed array notations are converted into pointer notation, so pointers can be used as array notations when we use ar[1] =10; it is converted as *(ar+1) =10; and pointer arithmetic methodes are used to solve the equation so pointer can also be used with array notation, so the basic behavior of pointer and array are similar, (taht's why we create run time array using pointer) p = (int *) malloc(5 * sizeof(int)); then we can use p[1].. p[2]... as well as *(p+1) *(p+2) too so the conclusion is 1. pointer is a variable , where array name is fixed 2. pointer takes 2 bytes where array is created as mentioned earlier 3. array notation are converted in pointer notations, 4. both stands for addresses. 5. array is group of variables where pointer is one variable
1 person likes this
@paki143 (793)
• Pakistan
14 Jan 07
i fully agree with the response fo sir dholey. i think u unerstand the major differnce between array and pointers of the response of sir dholey
@dholey (1383)
• India
17 Jan 07
thnaks to you , buti want to see the discussion owners comments too, and still i am waiting for that..
@dholey (1383)
• India
3 Feb 07
bala babu .. i am still waiting for your responses ...... are you an active member ... or ......
• India
11 Mar 07
Array name is a constant pointer .