What is base address? How is it associated differentiantly for one dimentional and 2 dimentional array?

Questions by dilip agrawal   answers by dilip agrawal

Showing Answers 1 - 6 of 6 Answers

jaydev

  • Nov 19th, 2007
 

base address is a actualy address of 0th element of an array and in two dimanstion
array it will 0(zero)th row and 0(zero)th coloum of array.

  Was this answer useful?  Yes

kbjarnason

  • Jul 1st, 2010
 

Note that C does not have two-dimensional arrays; it has arrays of arrays.

char a[10][20];

This is not a two-dimensional array; it is an array (with 10 elements) of arrays (each with 20 elements).

In the example, a is the base address of the array, the address of the first element of the array, _and_ the address of the first element _of_ the first element of the array... which is to say it is the address of:

   a (the whole thing)
   a[0]  (the first element)
   a[0][0] (the first element of a[0] )

For kicks, try this:

#include <stdio.h>

int main(void)
{
   char a[10][20];
   char b[10];

   printf( "sizeof a: %un", (unsigned) sizeof(a) );
   printf( "sizeof b: %un", (unsigned) sizeof(b) );
   printf( "sizeof a[0]: %un", (unsigned) sizeof(a[0]) );
   printf( "sizeof b[0]: %un", (unsigned) sizeof(b[0]) );
   return 0;
}

You should get:

  sizeof a: 200
  sizeof b: 10
  sizeof a[0]: 20
  sizeof b[0]: 1

Note that sizeof(a[0]) is _20_.  That's because a is not an array of characters, it is an array of _arrays_, where each element is an array of 20 characters.

  Was this answer useful?  Yes

Give your answer:

If you think the above answer is not correct, Please select a reason and add your answer below.

 

Related Answered Questions

 

Related Open Questions