Click here to Skip to main content
15,503,367 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
See more:
#include <stdio.h>
    int main(){ 


int  k=2,l=5;

printf("add of k+l is %d+%d\n",*(&k)+*(&l)); // why in output  in am getting not just 7 but  getting  out put  as 7+ addrss of k or  l 




return 0;
}


What I have tried:

I tried t sum by using address of varaible I am getting the desired result but getting address of k or l too
Posted
Updated 26-May-22 2:07am

1 solution

Nope, you're getting garbage, because, in the printf calls there are two %d format specifiers while only one value (*(&k)+*(&l)) is provided.
Try
C++
#include <stdio.h>
  
int main()
{
  int  k=2, l=5;

  printf("add of k+l is %d\n",*(&k)+*(&l));

  return 0;
}


Note, you could have made it simpler
C
#include <stdio.h>
  
int main()
{
  int  k=2, l=5;

  printf("add of k+l is %d\n", k+l);

  return 0;
}
 
Share this answer
 
v2
Comments
Patrice T 26-May-22 7:37am    
+5
CPallini 26-May-22 8:01am    
Thank you.

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900