Printf( "Memory size occupied by status1 : %d\n", sizeof(status1)) Let us check the following example to understand the concept − However as soon as you have 33 variables, it will allocate the next slot of the memory and it will start using 8 bytes. If you will use up to 32 variables each one with a width of 1 bit, then also the status structure will use 4 bytes. The above structure requires 4 bytes of memory space for status variable, but only 2 bits will be used to store the values. For example, the above structure can be re-written as follows − If you are using such variables inside a structure then you can define the width of a variable which tells the C compiler that you are going to use only those number of bytes. ![]() The C programming language offers a better way to utilize the memory space in such situations. This structure requires 8 bytes of memory space but in actual, we are going to store either 0 or 1 in each of the variables. Suppose your C program contains a number of TRUE/FALSE variables grouped in a structure called status, as follows −
0 Comments
Leave a Reply. |