This is a question from some book. When u run it u would get base address of the arguments provided
that is, if u write in CMD "myprog one two three"
then the address would be like 65521 n 65525 n 65529 Means equal byte consumption by all the arguments. And YES it would always give difference of no matter how long string u provide.
Could anyone please tell me, How did this happen ?????????????
Thanks in advance

/* myprog.c*/
#include<stdio.h>
#include<conio.h>

int main(int argc,char *argv[])
{
	int i;
	for(i=0;i<=3;i++)
	{
		printf("%u \n",&argv[i]);
	}

}
WaltP commented: U is not a word in English. Use full words as the Member Rules state. -4

Recommended Answers

All 4 Replies

printf("%u \n",&argv[i]);

This line, you are printing the "Unsigned decimal integer" (%u) for the memory address (&) of all the arguments given ("argv"). This --> &argv is the memory location of the argument 'i'

I am unsure if that is the answer you were looking for?

Those numbers have nothing to do with the amount of memory occupied by all those strings. Its nothing more than the starting memory address of them. If you want to display the length of the strings then you have to call strlen(), such as printf("%d\n", strlen(argv[i])); [edit]Oops! What ^^^ said :)

What?? Even I didn't understand what you guys said!

You are printing the address of the pointer to the string.

address 65521 contains the pointer to the string "one"
address 65525 contains the pointer to the string "two"
address 65529 contains the pointer to the string "three"

Change the line to be: printf("%u %u \n",&argv[i], argv[i]); or better yet printf("%p %p \n",&argv[i], argv[i]); since you are displaying addresses. argv[i] is the value you are looking for.

What?? Even I didn't understand what you guys said!

You are printing the address of the pointer to the string.

address 65521 contains the pointer to the string "one"
address 65525 contains the pointer to the string "two"
address 65529 contains the pointer to the string "three"

Change the line to be: printf("%u %u \n",&argv[i], argv[i]); or better yet printf("%p %p \n",&argv[i], argv[i]); since you are displaying addresses. argv[i] is the value you are looking for.

Thanks WaltP :P
Thread Solved

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.