When I compile this code, I get an output of 10 when it should be 0.
#include <iostream>
struct player
{
int hp;
int dmg;
};
void dealdamage(player x, player y)
{
y.hp = y.hp - x.dmg;
}
int main()
{
player p1, p2;
p1.hp = 10, p1.dmg = 10;
p2.hp = 10, p2.dmg = 10;
dealdamage(p1, p2);
std::cout << p2.hp << std::endl;
return 0;
}
Can anyone explain why?