DIGIT-ARC read-only archive · snapshot: July 23, 2026

arrays in c programming

8 posts · originally from https://geek.digit.in/community/threads/arrays-in-c-programming.30639/

V
vikas_r_s Original post #1
Jun 22, 2006 at 10:19 AM
hi everyone,
i am a newbi to programming.
can any one tell me in c language a two dimensional array name is of what type?
how come in arr[3][3], arr and *arr give same value(address)?
plsoft
plsoft #2
Jun 22, 2006 at 11:05 AM
when we use the '*' we are referring to the value of that variable (array in this case) which the pointer is pointing to, not the value of the pointer itself. However, if you use the 'address of' (&) operator, it will give the memory address of the variable it points to.
tuxfan
tuxfan #3
Jun 22, 2006 at 11:55 AM
Study the pointers well and you will understand this. Go for Pointers in C by Yashwant Kanetkar. Its a small book, worth its price. He will explain you pointers better than any of us. :) Pointers are pretty powerful (and desctructive if misused)!
V
Jun 22, 2006 at 10:07 PM
plsoft waht you say is true in a uni dimensional array.
but try the following code
int main()
{
int a[3][3];
printf("%d\n",a);
printf("%d\n",*a);
system("PAUSE");
return 0;
}

both printfs give same value i.e. memory address.HOW?
bukaida
bukaida #5
Jun 22, 2006 at 10:13 PM
The name of the array is the pointer to the first element of that array. Like wise a[5] and 5[a] will give you the same value. Go through the Kanitkar book(study the array and pointer chapter).
casanova
Jun 23, 2006 at 4:23 PM
Pointers is a very vast concept, there are dedicated books for it and yashwant kanetkar says "The no. of times your comp will hang is directly proportional to the no. of pointers you use".
BTW * mans value at
and & means address of.
So by using * u get the value.
ilugd
ilugd #7
Jun 23, 2006 at 4:57 PM
your array has 9 elements like if the first element is at memory loc 0 then the elements are there upto address 8.
a is from 0 to 8
a[0] is elements at 0,1,2
a[1] is elements at 3,4,5
a[2] is elements at 6,7,8

value of a is 0 and *a that is a[0] is 0 again. That is how i understand it. But my c is a bit rusty around pointers. Am I right anyone?
H
Jun 23, 2006 at 5:27 PM
vikas_r_s said:
hi everyone,
i am a newbi to programming.
can any one tell me in c language a two dimensional array name is of what type?
how come in arr[3][3], arr and *arr give same value(address)?

Sorry but i couldn't bear to read all the above responses and dunno if it has already been answered but here is how it is..

Since arr[3][3] is a 2D array you are basically creating a 2nd level pointer.
hence arr & *arr point to same address a[0][0]. to refer to the value use **arr .

And yes over use of pointer is lethal (for the brain:D)