I've seen structures declared differently by passing the struct name to malloc and returning a pointer...then the members are accessed like structname->member. what is the reason for this? I see this pattern a lot in C code, but don't know why it is done this way.
#include
#include
//typedef char user[25];
typedef struct
{
char name[25];
char password[12];
int id;
} User;
int main()
{
// typedef = reserved keyword that gives an existing datatype a "nickname"
User user1 = {"Bro", "password123", 123456789};
User user2 = {"Bruh", "password321", 987654321};
printf("%s
", user1.name);
printf("%s
", user1.password);
printf("%d
", user1.id);
printf("
");
printf("%s
", user2.name);
printf("%s
", user2.password);
printf("%d
", user2.id);
return 0;
}
You r so fuckin nice
This is what a chad do
Just found this channel. Bro Code is the giga-chad of programming tutorials!
to everyone here i advise you to code 1-2 examples to understand them fully it helped me alot
man at the end of the each tutorial when he says suscribe to become a fellow bro feels really good . a feeling of brotherhood (not gay )
thats pretty gay
Better than my Profs explanation, really appreciate the content.
bro you dont understand how much you have helped me right now lmfao
Seriously underranted videos. Well explained !
Awesome explanation, thank you
Quick and to the point, thanks bro.
Qht didn't you have to use strcpy() for the string in this one but we had to use that in the struct video?
Great explanation. Thank you.
Thank you so much you made C language so easy to understand
ur videos always help me :)
Thank u very much
nice and simple, do you have video explaining the arrow operator ?
short and helpful.
Quick and nice tutorial
You are the best ❤️
why r u not getting views?
bcz of your short titles !
but i like them ;)
Very understandable
I've seen structures declared differently by passing the struct name to malloc and returning a pointer...then the members are accessed like structname->member. what is the reason for this? I see this pattern a lot in C code, but don't know why it is done this way.
🔥🔥
So it basically just saves you from using the "struct" call to build a struct, doesn't really seem like too much of a time saver.
Hi im stupid. Why would this be prefered over using an array to hold the struct?
thanks!
thanks
ecstatic
Cool bruh
random comment
Done! here's my code:
#include
#include
#include
#include
#include
typedef struct{
char speciesName[40];
int legs;
bool endangered;
} animal;
int main(){
animal spider = {"Spider", 8 , false}; // Or at least I assume spiders aren't endangered.
printf("The %s is ", spider.speciesName);
if(spider.endangered){
printf("an endangered species ");
}
else{
printf("a non endangered species ");
}
printf("that has %d legs.", spider.legs);
}