Skip to content
← Back to Community
C structs
Profile icon
Jakman

A struct is a data structure creator that allows for basic Object oriented programming in C. Structs are made out side of the main function much like multiple classes in the same java/C# file. here is how it is done.

#include <stdio.h> struct mystruct{ int favoritenumber; char myName; }; int main(){ struct mystruct Jakman; Jakman.favoritenumber = 7; Jakman.myName = "Carlos"; printf("%i is his or her name and %i is their favorite number",Jakman.myName,Jakman.favoritenumber); }

The struct made is called mystruct and therefore is what it will be refrenced as from there on. I gave it some variables to be called later and closed the struct. The struct shows up in the main function. you have to call made structs in main by using the keyword struct followed by the name of the previously made struct and that is followed by whatever name you want to refrence that struct by. Then we give pass previously created variables to whatever the user wants. I personally made it to fit me. Then the individual values are printed out to the console and the program ends.
As always ask me questions if you need to. bye

Voters
Profile icon
YashvardhanJ1035
Profile icon
JulianoEletroni
Profile icon
ludovicana
Profile icon
davehazz
Profile icon
dldkgus9009
Profile icon
Jakman
Comments
hotnewtop
Profile icon
Ian29292

The main reason is that anyone can write an article. If you can read and write, you can write articles. Anyone can write an article at military to civilian resume writing services but not everyone can write a good one.