A small thought on the Basics Again

I was thinking about the following code

char *argv[] = { "Karthick", "88"};


so whats happening here. ??

Now to get you all clear of what my question is let me give an example. when we execute int a[] = { 12,13 }, the following would happen


a = &int(12); // note that the int(12) is called the address of which is assigned to a
a+1 = &int(13) // now new memory is allocated to 13 and that address is stored in a+1.

So the same what ll happen when the code in the beginning of the post is executed??

Using your terminology,

argv is the address of the pointer to "Karthick",
argv1 is the address of the pointer to "88".

Though this statement isn't true:
a+1 = &int(13) // now new memory is allocated to 13 and that address is stored in a+1.


the address of the integer 13 is not stored in a+1; it is a+1.
You created an array of two char* and each points to a string literal which cannot be modified. If you try to modify them you will cause undefined behavior within your program. To be honest I am not sure what your question is because the two arrays in question are totally different. One is an array of pointers. One is an array of integers.

In other words
*a == 12
*(a+1) = 13.

However,
*argv = address of first character of "Karthick"
*(argv+1) = address of first character of "88"

So in the case of argv it is an indirect access of each string through the pointer stored.
Oh ok.. Thanks Smith :)
Topic archived. No new replies allowed.