in this example
we do create the same variable twice
but here on the second time we are creating robots[3] using ROBOT (which is the same type as robot type)
why is it possible??
we are creating the same variable twice
Code:
#include <stdio.h>
typedef struct robot ROBOT;
struct robot {
char *name;
int energy;
};
int main() {
int i;
ROBOT robots[3]; //1st time
robots[0].name = "Lunar Lee";
robots[0].energy = 50;
robots[1].name = "Planetary Pete";
robots[1].energy = 20;
robots[2].name = "Martian Matt";
robots[2].energy = 30;
ROBOT robots[3] = { {"Lunar Lee", 50},{"Planetary Pete", 20},{"Martian Matt", 30} }; //2nd time