-5
#include<stdio.h>  
  
int add(int, int); // function prototype  
  
int main()  
{  
    int a, b;  
  
    // printf("Enter 2 integer numbers\n");  
    // scanf("%d%d", &a, &b);  
  
    //function call add(a, b);  
    printf(" %d + %d = %d \n", a, b, add(2, 7)); 

Please focus on this line why it gives address + 0 = 9//

    return 0;  
}  
  
//function definition  
int add(int x, int y)  
{  
    return x+y;  
}  

// produces outPut : 199164000 + 0 = 9

  • 5
    `a` and `b` are uninitialized, and it's not addresses, but a garbage values. – frippe Mar 18 '22 at 16:18
  • 1
    What output did _you_ expect? – Jabberwocky Mar 18 '22 at 16:21
  • Does this answer your question? [(Why) is using an uninitialized variable undefined behavior?](https://stackoverflow.com/questions/11962457/why-is-using-an-uninitialized-variable-undefined-behavior) – phuclv Mar 18 '22 at 16:40
  • It makes a lot more sense to put `int a = 2, b = 7;` and then `printf(" %d + %d = %d \n", a, b, add(a, b));` – Cheatah Mar 18 '22 at 18:33

2 Answers2

0

You commented the scanf function and also didn't given values for the a and b. So it printed garbage values. You also need to pass a and b into the add(a,b) function.

#include<stdio.h>  

int add(int, int); // function prototype  

int main()  
{  
    int a, b;  

    // printf("Enter 2 integer numbers\n");  
    scanf("%d%d", &a, &b);  

    //function call add(a, b);  
    printf(" %d + %d = %d \n", a, b, add(a, b)); 

    return 0;  
}  

//function definition  
int add(int x, int y)  
{  
    return x+y;  
}  
0

It is not printing any address. It is printing garbage values. You have not given any values to the variable a and b. So it will print garbage values. Why you commented scanf statement. Just stop commenting it and it will work.