you can imagine structures as some sort comparable to basic data objects as in objects orientated programming but there are some major differences as well which are the following:
c structures can only contain data members (variables) and not methods as in e.g. java. Therefore you canât define a constructors, destructors or other methods
c structures do not support encapsulation.
all the so called members are public by default and there isnât a build in way to change them to e.g. private or restrict their access in general.
c structures do not support inheritance or polymorphism (canât derive parent structure)
you have to manually free memory if you donât need it anymore. There is no âGarbage Collectorâ like in Java so the developer doesnât have to worry about memory.
you canât assign strings to the var like you learned above, but there is a function called strcpy()
//defining customer structure's membersstruct customer{ char fullName [50]; int age; char mailAddress [100];}int main(){ //creating a struct var struct customer firstCustomer; //accessing members of customer structure via '.' strcpy(fistCustomer.fullName, "Max Mustermann"); firstCustomer.age = 25; strcpy(fistCustomer.mailAddress, mustermann.max@googlemail.com); //different syntax struct testStructure{ int num; char letter; char word [30]; } struct testStructure test = {1, "a", "some text"} //using this syntax you don't have to use the strcpy() method return 0;}