How to get the size in chars of a member of a struct in C

1 Answer

0 votes
#include <stdio.h> 

// 1 byte = 1 char

typedef struct
{
    int id;
    char name[32];
} employee;
 
   
int main(void)
{   
    employee e;
    
    int size_in_chars = sizeof(e.id);
    printf("%d\n", size_in_chars);
     
    size_in_chars = sizeof(e.name);
    printf("%d\n", size_in_chars);
     
    return 0;
}
 
 
         
/*
run:
      
4
32
     
*/

 



answered Jul 3, 2024 by avibootz

Related questions

3 answers 169 views
2 answers 115 views
2 answers 153 views
153 views asked Apr 28, 2022 by avibootz
1 answer 252 views
1 answer 170 views
1 answer 127 views
...