C - sizeof on structure

Description

sizeof on structure

Demo

#include <stdio.h> 

int main() //from  w w w  .  j a v a 2 s .co  m
{ 
   struct robot { 
       int alive; 
       char name[5]; 
       int xpos; 
       int ypos; 
       int strength; 
   }; 

   printf("The evil robot struct size is %u\n", 
           sizeof(struct robot)); 
   return(0); 
}

Result

The sizeof operator works on all variable types, but for a structure, specify the structure itself.

Use the keyword struct followed by the structure's name.

The size of the structure is determined by adding up the storage requirement for each of its elements.

Related Topic