How is memory allocated in int array

前端 未结 5 1694
南笙
南笙 2021-01-05 06:28

How much space does a int array take up? Or how much space (in bytes) does a int array consumes that looks something like this:

 int[] SampleArray=new int[         


        
5条回答
  •  生来不讨喜
    2021-01-05 07:25

    It depends on both the language, but moreover to the operating system.

    You need 4 integers. Normally an integer is 2 or 4 bytes (mostly 4 on most systems), but to be sure check sizeof(int).

    (Also keep in mind the values can be differently represented depending on the operating system), like MSB first or LSB first (or a mix in case 4 bytes are used).

提交回复
热议问题