lundi 5 juillet 2021

Getting wrong output from summation

I have just set up VS code for C++ today and I tried to check if everything works perfectly. First I tried to print "Hello World" and it worked. Then I wrote this:

#include <stdio.h>

int main()
{
    int x = 10, y = 20, z;
    z = x + y;
    printf("%d + %d = %d", &x, &y, &z);
    return 0;
}

After running that simple code, I got an output: 6422220 + 6422216 = 6422212

What did go wrong?

Aucun commentaire:

Enregistrer un commentaire