Code:
#include <stdio.h>
typedef struct ro RO;
struct ro {
char *address;
int id;
int no;
float velocity;
};
void info(RO r); /* declare functions */
void harm(RO *r);
int main() {
RO r1 = {"Man Main", 140, 213, 5.1};
RO r2 = {"Pla Pet", 170, 309, 4.5};
RO *ptr_r1 = &r1;
printf("Before damage: \n\n");
info(r1);
info(r2);
harm(ptr_r1);
harm(&r2);
printf("\nAfter damage: \n\n");
info(r1);
info(r2);
return 0;
}
void info(RO r) {
printf("%s: id: %d IQ: %d ", r.address, r.id, r.no);
printf("Velocity: %0.1f\n", r.velocity);
}
void harm(RO *r) {
r->id -= 20;
r->velocity -= 1;
}
Bookmarks