0

Need help in memory address calculations

Given is a `rectype` matrix A[121][4][5]. The address of A[20][2][3] is 2160. What is the size of `rectype` if the starting address is 2000? I keep on getting 0.39 bytes but is that even possible? Quiz is finished but I'm curious as to how one can get the correct answer.

22nd Jan 2021, 7:23 AM
Anthony Aromin
Anthony Aromin - avatar
5 Respuestas
+ 2
Shiina You are concerned and I am sad. How come no one ever thought about, or see it for 5 years+ I have no idea. Teachers shouldn't be just "doing the job" following the syllabus without any concern for student's future. Even syllabus was written by human, so it's just normal if there's a flaw. Idk how, you (as a student) can correct this mistake when even teachers don't mind about it. Things become somewhat twisted when bureaucracy is involved, sadly.
23rd Jan 2021, 10:18 AM
Ipang
+ 1
You haven't specified a relevant language in the thread tags above. Language context clarity is important cause not all languages support memory address manipulation. P.S. size of an object depends on its type or underlying types. For arrays, dimensions also affect object size. Your speculation about how start address affects an object's size is questionable.
23rd Jan 2021, 4:20 AM
Ipang
+ 1
Ipang `rectype` is a Record. There was a code given to us in Java but the size of data types taught to us was for C. The original size of `rectype` based on the sizes of data types taught to us is 17. But we were told to assume that we don't know the size of `rectype` but only the starting address and the address of one of its elements (as given in the post above). I don't speculate that start address affects object size. I know it doesn't. I only assumed that the matrix was stored in memory in row-wise order and did some arithmetic to arrive at 0.39 bytes. It turns out i got it wrong because the answer was not supposed to be rounded off. Now I'm wondering if it's even possible to have 0.387409 bytes as the answer because I'm not sure what data types `rectype` has because it's less than 1 byte. P.S. We were taught that if an int array of size 2 was stored at address 3000... the first int is stored at 3000 and the next int is stored at 3002 because int has a size of 2 bytes.
23rd Jan 2021, 6:33 AM
Anthony Aromin
Anthony Aromin - avatar
+ 1
Shiina In C/C++ data type size (most notably integer types) is not strictly defined as you were told. It is advised of us to use `sizeof` operator to check for size of a certain type rather than relying on some theory. Anyways, is this quiz from SoloLearn or from your college? I agree that no data type has size less than 1 byte, at least for C/C++. So 0.39 byte just doesn't make sense.
23rd Jan 2021, 8:37 AM
Ipang
+ 1
Ipang It's from my college. And I'm kind of concerned because they've been giving this exact same quiz to students for at least 5 years.
23rd Jan 2021, 9:31 AM
Anthony Aromin
Anthony Aromin - avatar