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 193 views
2 answers 129 views
2 answers 164 views
164 views asked Apr 28, 2022 by avibootz
1 answer 273 views
1 answer 181 views
1 answer 144 views
...