Hi,
Are 2D arrays positioned in memory the same way as normal arrays?
ex.:

char names[2][5] = {"Dean", "Viky"};

If 'names' is memory location 3000, are the letters necessarily stored like this?

3000 = 'D'
3001 = 'e'
3002 = 'a'
3003 = 'n'
3004 = '\0'
3005 = 'V'
3006 = 'i'
3007 = 'k'
3008 = 'y'
3009 = '\0'

thanks.

hi
if there is enuph memory your way is corect but there is'nt with same way saved but not foollow

I think it is stored as

names[0]="Dean"// pointer to the starting character of the string "Dean"
names[1] ="Viky"// pointer to the starting character of the string "Viky"

And "Dean" and "Viky" is hold as two another array of characters in another place in memory.

Hi,
Are 2D arrays positioned in memory the same way as normal arrays?
ex.:

char names[2][5] = {"Dean", "Viky"};

If 'names' is memory location 3000, are the letters necessarily stored like this?
...

An easy way to find out is to create the array in main() then pass the array to a function like output(names) . Then output the contents of the pointer one character at a time in hex.

void output(char *p)
{
    int i;
    for (i=0; i<10; i++)
    {
        printf("%2d) %02Xh\n", i, *p); // output the character at the ptr
        p++;   // point at the next character
    }
}

Yes, I used printf() for the output because of the C++ iomanip foolishness -- it makes little sense and this was faster.

> If 'names' is memory location 3000, are the letters necessarily stored like this?
Yes.

> And "Dean" and "Viky" is hold as two another array of characters in another place in memory.
No.
The OP had a true 2D array, so all the data is contiguous in memory.

Your answer is correct for.
char *names[2] = {"Dean", "Viky"};

OK thanks guys...

Now can anybody tell me....
Is there any way literal values can be passed to a function which accepts an object, instead of passing an object?

What I mean is...

Coords screenPosition;
screenPosition.xPos = 40;
screenPosition.yPos = 12;

locateXY(screenPosition);

is there any way I can pass 40 and 12 to locateXY() without having to create an object?

thanks...

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.