Show memory consumption of arrays with different data types. This teaches memory optimization.
Logic: Calculate array size = elements × sizeof(type)
No user input.
Arrays of different data types are defined in the program.
Memory used by each array.
• Array size is fixed
• Memory depends on data type size
• System architecture affects size
Each array consumes memory based on:
• number of elements
• size of each element
Bigger data types use more memory.
1.Decide number of elements in array (for example n = 5).
2.Create arrays of different data types.
3.Find size of one element using sizeof(type).
4.Calculate total memory:
• array_size = n × sizeof(type)
5.Print memory used by each array.