[ Prev ]
2021-11-03

-- Nov 2 In-Class Exercise Thread
How much memory would be allocated by the C compiler for this array?
3*4*4 bytes = 48 bytes
How would the values be written in memory?
0 1 2 3 4 5 6 7 8 9 10
(Edited: 2021-11-03)
How much memory would be allocated by the C compiler for this array? 3*4*4 bytes = 48 bytes How would the values be written in memory? 0 1 2 3 4 5 6 7 8 9 10

-- Nov 2 In-Class Exercise Thread
C would allocate 48 bytes for the array. it would be stored in the following order: 0,1,2,3,4,5,6,7,8,9,10,11
(Edited: 2021-11-03)
C would allocate 48 bytes for the array. it would be stored in the following order: 0,1,2,3,4,5,6,7,8,9,10,11

-- Nov 2 In-Class Exercise Thread
Approximately 48 bytes of memory would be allocated by the C compiler for this array due to the fact that an int is 4 bytes and the array has a size of 12. The values would be written like: {0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11} a[0][1] would look like: 0000 0000 0000 0000 0000 0000 0000 0001
(Edited: 2021-11-03)
Approximately 48 bytes of memory would be allocated by the C compiler for this array due to the fact that an int is 4 bytes and the array has a size of 12. The values would be written like: {0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11} a[0][1] would look like: 0000 0000 0000 0000 0000 0000 0000 0001

-- Nov 2 In-Class Exercise Thread
This is an array of size 3x4 of int elements. So we would implement this by linearizing it into a single dimension array of size 3*4=12. Thus, the amount of memory allocated by the C compiler for this array will be 12*sizeof(int) = 12*4 = 48 bytes. The values will be written as: 00 01 02 03 04 05 06 07 08 09 0A 0B where 00 represents the bytes for 0, 01 represents the bytes for 1, and so on.
(Edited: 2021-11-03)
<nowiki>This is an array of size 3x4 of int elements. So we would implement this by linearizing it into a single dimension array of size 3*4=12. Thus, the amount of memory allocated by the C compiler for this array will be 12*sizeof(int) = 12*4 = 48 bytes. The values will be written as: 00 01 02 03 04 05 06 07 08 09 0A 0B where 00 represents the bytes for 0, 01 represents the bytes for 1, and so on.</nowiki>

-- Nov 2 In-Class Exercise Thread
The C compiler would allocate 48 bytes for this array. In memory it would be stored row by row: {0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11}
The C compiler would allocate 48 bytes for this array. In memory it would be stored row by row: {0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11}

-- Nov 2 In-Class Exercise Thread
 48 bytes, 4 bytes * 12 ints
 the ints would be stored in order
 in memory:
 0000 0000 0000 0000 0000 0000 0000 0000
 0000 0000 0000 0000 0000 0000 0000 0001
 0000 0000 0000 0000 0000 0000 0000 0010
 0000 0000 0000 0000 0000 0000 0000 0011 
 0000 0000 0000 0000 0000 0000 0000 0100
 0000 0000 0000 0000 0000 0000 0000 0101
 0000 0000 0000 0000 0000 0000 0000 0110
 0000 0000 0000 0000 0000 0000 0000 0111
 0000 0000 0000 0000 0000 0000 0000 1000
 0000 0000 0000 0000 0000 0000 0000 1001
 0000 0000 0000 0000 0000 0000 0000 1010
 0000 0000 0000 0000 0000 0000 0000 1011
(Edited: 2021-11-03)
48 bytes, 4 bytes * 12 ints the ints would be stored in order in memory: 0000 0000 0000 0000 0000 0000 0000 0000 0000 0000 0000 0000 0000 0000 0000 0001 0000 0000 0000 0000 0000 0000 0000 0010 0000 0000 0000 0000 0000 0000 0000 0011 0000 0000 0000 0000 0000 0000 0000 0100 0000 0000 0000 0000 0000 0000 0000 0101 0000 0000 0000 0000 0000 0000 0000 0110 0000 0000 0000 0000 0000 0000 0000 0111 0000 0000 0000 0000 0000 0000 0000 1000 0000 0000 0000 0000 0000 0000 0000 1001 0000 0000 0000 0000 0000 0000 0000 1010 0000 0000 0000 0000 0000 0000 0000 1011

-- Nov 2 In-Class Exercise Thread
There will be 48 bytes of memory allocated to the array (12 * 4 bytes per int). The values would be written in memory like this: | 0 | 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | The last element of this array (11) would contain 4 bytes (32 bits) like so: 0000 0000 0000 0000 0000 0000 0000 1011
(Edited: 2021-11-03)
<nowiki> There will be 48 bytes of memory allocated to the array (12 * 4 bytes per int). The values would be written in memory like this: | 0 | 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | The last element of this array (11) would contain 4 bytes (32 bits) like so: 0000 0000 0000 0000 0000 0000 0000 1011 </nowiki>

-- Nov 2 In-Class Exercise Thread
Int size in C = 4 Bytes Total memory allocated to 2D Array
                = Number of Rows * Number of Columns * Size of one element
                = 3 * 4 * 4 Bytes
                = 48
48 Bytes would be allocated by the C Complier
Say the base address is 4000 address: 4000 value: 0 //a[0][0] address: 4004 value: 1 //a[0][1] ... address: 4016 value: 4 //a[1][0]
Int size in C = 4 Bytes Total memory allocated to 2D Array = Number of Rows * Number of Columns * Size of one element = 3 * 4 * 4 Bytes = 48 48 Bytes would be allocated by the C Complier Say the base address is 4000 address: 4000 value: 0 //a[0][0] address: 4004 value: 1 //a[0][1] ... address: 4016 value: 4 //a[1][0]

-- Nov 2 In-Class Exercise Thread
12 int numbers so 12 * 4 = 48 bytes or 192 bits stored in each row starting from 0 = {0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11} From a[0][1] it will be 0000 0000|0000 0000|0000 0000|0000 0001 and so on
(Edited: 2021-11-03)
12 int numbers so 12 * 4 = 48 bytes or 192 bits stored in each row starting from 0 = {0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11} From a[0][1] it will be 0000 0000|0000 0000|0000 0000|0000 0001 and so on

-- Nov 2 In-Class Exercise Thread
 3 * 4 = 12 elements
 12 * 4 bytes = 48 bytes for all 12 ints
 to write into memory, one single dimension array will be created with size 12. 
 the first row will be written in the first 4 elements, the next row written in the 
 second 4 elements, and the last row written in the last 4 elements, which results 
 in { 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11 }. 
 They would then be written in this order into memory. 
 For example, the 9th entry would look like
 0000 0000 0000 0000 0000 0000 0000 1000
(Edited: 2021-11-03)
3 * 4 = 12 elements 12 * 4 bytes = 48 bytes for all 12 ints to write into memory, one single dimension array will be created with size 12. the first row will be written in the first 4 elements, the next row written in the second 4 elements, and the last row written in the last 4 elements, which results in { 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11 }. They would then be written in this order into memory. For example, the 9th entry would look like 0000 0000 0000 0000 0000 0000 0000 1000
[ Next ]
X