About structs or structures in C ..

Home Forums C-programming.. About structs or structures in C ..

Viewing 1 post (of 1 total)
  • Author
    Posts
  • #2232 Reply
    Humble
    Keymaster

    What is it ?

    To store a ‘record’ type data we use it : That said, it is a collection of different data types which are grouped together and each element in a C structure is called member.

    struct tagname {
     int x;
     char a[10];
     ....etc
    }junk;
    
    
    tagname is optional , but better to use it ! because you may need to create struct variables later.. At the same time, mostly you could make use of "typedef" to get rid of structure tags..
    
    To access structure members you can use 'memberof' operator , nothing but ".".
    
    for ex:
    
     junk.x 
    
    You can not use the same structure member name in another structure..
    
    if the structure contains pointers , you can't initialize this struct at declaration time.
    
    Also note that, the space need to be allocated and deallocated for the pointer members of the struct individually.. It is a best practice to initialize a structure to null while declaring, if we don’t assign any values to structure members.
Viewing 1 post (of 1 total)
Reply To: About structs or structures in C ..
Your information: