C structs

Your video will begin in 10
65 Views
Published
C structs tutorial example explained

#C #struct #structs

struct Player
{
char name[12];
int score;
};

int main()
{
// struct = collection of related members ("variables")
// they can be of different data types
// listed under one name in a block of memory
// VERY SIMILAR to classes in other languages (but no methods)

struct Player player1 = {"Bro", 4}
struct Player player2 = {"Bra", 5}

//strcpy(player1.name, "Bro");
//player1.score = 4;

//strcpy(player2.name, "Bra");
//player2.score = 5;

printf("%s\n", player1.name);
printf("%d\n", player1.score);

printf("%s\n", player2.name);
printf("%d\n", player2.score);

return 0;
}
Category
Bro Code
Tags
c programming, programming, tutorial
Be the first to comment