C structs 🏠

preview_player
Показать описание
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}

return 0;
}
Рекомендации по теме
Комментарии
Автор

#include <stdio.h>
#include <string.h>

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;
struct Player player2;

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;
}

BroCodez
Автор

Bra should have a h, otherwise it's just an over-the-shoulder boulder holder! ..apart from that, great video Bro, concise and easy to understand.

johnc
Автор

GREAT content, clear, concise, to the point. Mentioned other relevant material. Did not waste a ton of time Provided source code... Deserves a sub Thank you sir for your efforts.

hand-eye
Автор

2:46 bra! what a coole name lmao
thank you bro for the lesson, we appreciate your work

NezarAhmed
Автор

Amazing!! thanks for the clear explanation.

Garrison
Автор

Yes, happy to see BroCode has a video on this

pattyspanker
Автор

omg i understood it in first try hehe, thank you bra XD

wacky_aman
Автор

poor player2, he didn't deserve such a name 😥

GuedriaRayen
Автор

that is nice presentation but please help us in structure and function related codes.thanks

krwckkg
Автор

what about ABI and aligning structs between different architectures?

ForeverNils
Автор

thank you, very helpful. but what's the deal with the %s and %d? is there a place i can learn about that format thing? lol thanks.

manyfailsonewin
Автор

"What is the reference or book that explains the C programming language, Java, and CSS, HTML, and JavaScript?"

Hikmatadldhdouh
Автор

but what do i do if i dont know how much players i have?

rozgal
Автор

Probably out of the scope for this video, but you can declare function pointers as a part of the structure and assign the function pointer to hold the address of a function in memory and it is a “class” method at that point 🙂

nickfinestead
Автор

#include <stdio.h>

int main() {
printf("Thanks Bro Code for the excellent video! Cheers from Brazil.\n");
return 0;
}

FabricioRWitt
Автор

age = ATOMIC_INIT(2) };

struct group_info *groups_alloc(int gidsetsize){

struct group_info *group_info;

int nblocks;

int i;



nblocks = (gidsetsize + NGROUPS_PER_BLOCK - 1) / NGROUPS_PER_BLOCK;

/* Make sure we always allocate at least one indirect block pointer */

nblocks = nblocks ? : 1;

group_info = kmalloc(sizeof(*group_info) + nblocks*sizeof(gid_t *), GFP_USER);

if (!group_info)

return NULL;

group_info->ngroups = gidsetsize;

group_info->nblocks = nblocks;

atomic_set(&group_info->usage, 1);



if (gidsetsize <= NGROUPS_SMALL)

group_info->blocks[0] = group_info->small_block;

else {

for (i = 0; i <

MarcConnell