Close
Close

If we command '&<variable>' instead of '<variable>' beside '%d' in the printf() statement, then what does it print?

   codebloodedKaran

For example,
If I code:

int a=10;
printf("%d\n",&a);

instead of the standard way:

int a=10;
printf("%d\n",a);

then what does it print?


Answers

  •   

    It print’s the address that ‘a’ is pointing to,but the syntax is not  correct so the compiler will give a warning(the code is going to execute tho).

    For more info refer to point me chapter.



  •   

    &a is the address of the variable a. Addresses make sense only as unsigned numbers while %d is used to print signed integers. So if we try to print the address of a variable using %d, we may get a positive or negative value depending on the address. There is no real significance to that.

    You should use %u for printing the address of a variable because it treats the integer as unsigned. 



  •   

    It will print the address of  a



Ask Yours
Post Yours
Write your answer