in Education by
I know that the U literal means in c, that the value is a unsigned integer. An unsigned intagers size is 4 bytes. But how big are 2U or 1024U? Does this simply mean 2 * 4 bytes = 8 bytes for example or does this notation means that 2 (or 1024) are unsigned integers? My goal would be to figured out how much memory will be allocated if i call malloc like this int *allocated_mem = malloc(2U * 1024U); and prove in a short program my answer what i tried like this printf("Size of 2U: %ld\n", sizeof(2U)); printf("Size of 1024U: %ld\n", sizeof(1024U)); I would have expeted for the first line a size of 2 * 4 Bytes = 8 and for the second like 1024 * 4 Bytes = 4096 but the output is always "4". Would realy appreciate what 2U and 1024U means exactly and how can i check their size in C? JavaScript questions and answers, JavaScript questions pdf, JavaScript question bank, JavaScript questions and answers pdf, mcq on JavaScript pdf, JavaScript questions and solutions, JavaScript mcq Test , Interview JavaScript questions, JavaScript Questions for Interview, JavaScript MCQ (Multiple Choice Questions)

1 Answer

0 votes
by
My goal would be to figured out how much memory will be allocated if i call malloc like this int *allocated_mem = malloc(2U * 1024U); What is difficult about 2 * 1024 == 2048? The fact that they are unsigned literals does not change their value. An unsigned intagers size is 4 bytes. (sic) You are correct. So 2U takes up 4-bytes, and 1024U takes up 4-bytes, because they are both unsigned integers. I would have expeted for the first line a size of 2 * 4 Bytes = 8 and for the second like 1024 * 4 Bytes = 4096 but the output is always "4". Why would the value change the size? The size depends only on the type. 2U is of type unsigned int, so it takes up 4-bytes; same as 50U, same as 1024U. They all take 4-bytes. You are trying to multiply the value (2) times the size of the type. That makes no sense.

Related questions

0 votes
    I know that the U literal means in c, that the value is a unsigned integer. An unsigned intagers ... JavaScript Questions for Interview, JavaScript MCQ (Multiple Choice Questions)...
asked May 4, 2022 in Education by JackTerrance
+1 vote
    Which operator can be used to determine the size of a data type or variable in C Programming?...
asked Nov 9, 2020 in Technology by JackTerrance
+1 vote
    Which built-in library function can be used to re-size the allocated dynamic memory in C-Programming?...
asked Nov 9, 2020 in Technology by JackTerrance
0 votes
    What is the size of wchar_t in C++? a) Based on the number of bits in the system b) 2 or 4 c) 4 d) 2...
asked Oct 19, 2022 in Education by JackTerrance
0 votes
    So my professor gave me (where x is a C executable): $ ./x y z w He said the memory ... questions, JavaScript Questions for Interview, JavaScript MCQ (Multiple Choice Questions)...
asked Jan 15, 2022 in Education by JackTerrance
0 votes
    If page size of 1MB memory is 1 KB then the number of higher order bits of address bus used to denote page number is ( ... (c) 12 (d) 9 Select the correct answer from above options...
asked Dec 17, 2021 in Education by JackTerrance
0 votes
    Push (10), Push (20), Pop, Push (10), Push (20), POP, Pop, Pop 2x Implement a c program to stack ... 20), Pop & draw final output. Select the correct answer from above options...
asked Dec 5, 2021 in Education by JackTerrance
0 votes
    out of the following heading tags, which tag cause the browser to render text at the largest default size? a) b) c) d) Select the correct answer from above options...
asked Nov 30, 2021 in Education by JackTerrance
0 votes
    Push (10), Push (20), Pop, Push (10), Push (20), POP, Pop, Pop 2x Implement a c program to stack ... 20), Pop & draw final output. Select the correct answer from above options...
asked Nov 26, 2021 in Education by JackTerrance
0 votes
    Implement a c program to stack size - 8 for Push (10), Push (20), Pop, Push (10), Push (20), POP, ... 20), Pop & draw final output. Select the correct answer from above options...
asked Nov 26, 2021 in Education by JackTerrance
0 votes
    Push (10), Push (20), Pop, Push (10), Push (20), POP, Pop, Pop 2x Implement a c program to stack ... 20), Pop & draw final output. Select the correct answer from above options...
asked Nov 25, 2021 in Education by JackTerrance
0 votes
    Implement a c program to stack size - 8 for Push (10), Push (20), Pop, Push (10), Push (20), POP, ... 20), Pop & draw final output. Select the correct answer from above options...
asked Nov 25, 2021 in Education by JackTerrance
0 votes
    Which one of the following is the smallest in size? (a) Bacteria (b) Mitochondrion (c) ... Science,Science proposed by,electromagnetic theory engineering physics,Science nptel...
asked Nov 8, 2021 in Education by JackTerrance
0 votes
    What is the size of a void pointer in C?...
asked Jan 21, 2021 in Technology by JackTerrance
0 votes
    What are the size classes in Objective-c?...
asked Nov 10, 2020 in Technology by JackTerrance
...