-
Notifications
You must be signed in to change notification settings - Fork 2
/
Bit_or_Memory_assign.c
37 lines (29 loc) · 954 Bytes
/
Bit_or_Memory_assign.c
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
// author: jaydattpatel
#include <stdio.h>
#include <string.h>
/* define simple structure */
struct {
unsigned int widthValidated; // asigned only 4bytes
unsigned int heightValidated; // asigned only 4bytes
} status1;
/* define a structure with bit fields */
struct {
unsigned int widthValidated : 1; // asigned only 1bits and it can save 0 or 1 value
unsigned int heightValidated : 1; // asigned only 1bits and it can save 0 or 1 value
} status2;
struct {
unsigned int age : 3; // asigned only 3bits and it can save 0-7 value
} Age;
int main( )
{
printf( "Memory size occupied by status1 : %d\n", sizeof(status1));
printf( "Memory size occupied by status2 : %d\n", sizeof(status2));
printf( "Sizeof( Age ) : %d\n", sizeof(Age) );
Age.age = 4;
printf( "Age.age : %d\n", Age.age );
Age.age = 7;
printf( "Age.age : %d\n", Age.age );
Age.age = 8;
printf( "Age.age : %d\n", Age.age );
return 0;
}