C Programming Lab Manual – 65

Write a C program for Memory Allocation using Bytes and Bits.

1. Include the standard input/output library. 
2. Define the main function.
   1. Declare variables: Memory_A as integer, Memory_B as float,
      Memory_C as char, Memory_D as double, Memory_Str as String.
   2. Print a comment to show memory state.
   3. Assign the value 10 to Memory_A.
   4. Assign the value 10.12345 to Memory_B.
   5. Assign the character 'A' to Memory_C.
   6. Assign the value 10.123456789 to Memory_D.
   7. Assign the string "Anisur" to Memory_Str.
   8. Print the size of Memory_A in bytes or bits.
   9. Print the size of Memory_B in bytes or bits.
   10. Print the size of Memory_C in bytes or bits.
   11. Print the size of Memory_D in bytes or bits.
   12. Print the size of Memory_Str in bytes or bits.
   13. End the main function and return 0.
3. End of program.

#include <stdio.h>

int main()
{
    //!showMemory()
    int Memory_A = 10;
    float Memory_B = 10.12345;
    char Memory_C = 'A';
    double Memory_D = 10.123456789;
    char Memory_Str[10] = "Anisur";
    
    printf("The size of Memory of int, Memory_A = %zu Bytes or %lu bits\n",sizeof(Memory_A),sizeof(Memory_A)*8);
    printf("The size of Memory of float, Memory_B = %zu Bytes or %lu bits\n",sizeof(Memory_B),sizeof(Memory_B)*8);
    printf("The size of Memory of char, Memory_C = %zu Bytes or %lu bits\n",sizeof(Memory_C),sizeof(Memory_C)*8);
    printf("The size of Memory of double, Memory_A = %zu Bytes or %lu bits\n",sizeof(Memory_D),sizeof(Memory_D)*8);
    printf("The size of Memory of Str, Memory_Str = %zu Bytes or %lu bits\n",sizeof(Memory_Str),sizeof(Memory_Str)*8);
    return 0;
}

The size of Memory of int, Memory_A = 4 Bytes or 32 bits
The size of Memory of float, Memory_B = 4 Bytes or 32 bits
The size of Memory of char, Memory_C = 1 Bytes or 8 bits
The size of Memory of double, Memory_A = 8 Bytes or 64 bits
The size of Memory of Str, Memory_Str = 10 Bytes or 80 bits