main( )

{

   int i=10,j=20;
   printf("%d%d",&i,&j);
   return 0;

}

When i executing this code: I got the address values like -12, -10, -20

Is it the address are in negative values or I am doing a mistake in the program.

please give the solution it's urgent.

When you want to print an address, you use the %p format modifier, and for extra safely cast the value to void*:

printf("%p\t%p\n", (void*)&i, (void*)&j);

Or use %u as addresses are of the type unsigned int.

Or use %u as addresses are of the type unsigned int.

I'll have to agree with Ed here. %p is specifically for pointer addresses, so why use %u? Click .

That like putting a garbageback over your clothes and calling it a raincoat :)

Agree with Ed and Nick -- %p will display the address in hex values, while %u will display it as an unsigned integer. Which one to use really depends only on how you want to view the address. IMO hex is preferable.

Okay. I've got to accept it, %p would be better.

I'd like to state for the record, that I agree with Ed, Nick, Dragon, and Jishnu the Second.


.

commented: Nice to know that you sometimes actually agree with someone ;) +6

hi,


i know this is true,this -10and -20 is address of that int,
int a=10;
means a is a intger type which is having the value of 10
and*a is a is having a address of a means 10 .
i think look at c book .take a guide from basic of c.

with regards
MONIKA

main( )

{

   int i=10,j=20;
   printf("%d%d",&i,&j);
   return 0;

}

When i executing this code: I got the address values like -12, -10, -20

Is it the address are in negative values or I am doing a mistake in the program.

please give the solution it's urgent.

or use %x to view the address of i and j in hex values...
If u r a real embedded engineer u wil love to see hex values of address ....(because tat is most understandable......)

1.#include<stdio.h>
2.main( )
3.
4.{
5.
6. int i=10,j=20;
7. printf("%d %d",i,j);
8. return 0;
9.
10.}
u just need to modify the printf statement
& is always used in scanf