Question: Write down theexact step-by-step execution of this code and it's... Write down theexact step-by-step execution of this code and it's output. Full marks will be

Write down theexact step-by-step execution of this code and it's...

Write down theexact step-by-step execution of this code and it's output. Full marks will be awarded for writing down the steps in correct order describing the exact execution of the code. Partial marks may be awarded for submissions that are missing minor details.

01#include

02

03#define INITIAL_HEALTH 100

04#define NAME_LENGTH 10

05

06struct Hero

07{

08char name[NAME_LENGTH + 1];

09int health;

10int strength;

11int shield;

12};

13

14struct Hero attack(struct Hero* h1, struct Hero* h2)

15{

16struct Hero result;17

18while (h1->health > 0 && h2->health > 0)

19{

20h1->health -= h2->strength - h1->shield;

21h2->health -= h1->strength - h2->shield;

22}

23

24if (h1->health < h2->health)

25{

26result = *h1;27}

28else

29{

30result = *h2;

31}

32

33return result;

34}

35

36int main(void)

37{

38struct Hero hero1 = { {'N', 'i', 'n', 'j', 'a', ''} , INITIAL_HEALTH, 150, 20 };

39struct Hero hero2 = { "Enigma", INITIAL_HEALTH, 75, 50 };

40

41struct Hero winner = attack(&hero1, &hero2);

42

43puts("Game Over");

44printf("The winner is %s", winner.name);

45

46return 0;

47}

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related General Management Questions!