Assuming a standard computer system (float and int types get 4 bytes of memory,
ID: 3889024 • Letter: A
Question
Assuming a standard computer system (float and int types get 4 bytes of memory, short type gets 2 bytes of memory, and long type gets 8 byte memory) with the memory structure as shown in Figure 7.1.1 determine the output of the following statements when they are executed as part of complete programs.
2) char val1= 'm'; // 1000
int val2 = 13; // 1004
cout << &val2;
&val2 is 1004
4) short x1 = 21, x2 = 14, x3 = 89; // 1000, 1002, 1004
float y1 = 3.452 // 1006
cout << &y1;
&y1 is 1006
6) float s1 = 3.2;
short x1 = 3, x2 = 5;
int x3 = 2456;
cout << &x1 << endl << &x3;
&x1 = 1004 and &x3 = 1008
8) Write C++ statement to store the value 487 in a short type memory cell, and to store the value 7.34 in a float type memory cell and to print the address of these values.
float val1 = 7.34;
short val2 = 487;
cout << &val1 << endl << &val2;
This is what I got are they correct? if not please explain why and how you came up with the coreect solution
d file:///Users/K-Hype/Downloads/C++Book-Ch7-Pointers-201 6%20(1).pdf Microsoft Word -C++Book-Ch7-Pointers-2016 1 / 50 7.1. Anatomy of Memory and "Address of" Operator& Recall that a byte of memory is the amount of memory needed to store one character data. One byte is equal to 8 bits or 8 circuits. The entire memory is made of millions of bytes. For the purpose of conveniently managing the memory, each byte of the memory is given an address. These addresses are contiguous numbers. Though the actual memory addresses are hexa-decimal coded numbers, for simplicity, we can use the decimal equivalent of them to identify the individual memory cells. So, each byte of memory has a number that identifies it. This is analogous to each mail box on a street having an address written on it for the mail-man to identify and put each mail in the right mail box. Figure 7.1.1 shows a set of memory bytes that begin with the address 1000 Here we use 1000 as the beginning address for illustrative purposes. Actual addresses may are different and they are coded in hexa-decimal coding system. The numbered boxes shown in the figure represent bytes of memory. For the purposes of our discussion, we shall assume this to be the memory of the computer system that we are working with. 1003 1004 1005 1006 1007 1008 1009 1010 1011 1013 1014 1015 10016 1017 1018 1019 1020 1021 1022 1023 1024 Figure 7·LL Memory bytes and their addressesExplanation / Answer
2) char val1= 'm'; // 1000 char data type needs one byte only
int val2 = 13; // 1001 val2 can be stored at address 1001,1002,1003,1004 --- 4 bytes for int
cout << &val2;
&val2 is 1001
4) short x1 = 21, x2 = 14, x3 = 89; // 1005, 1007, 1009 2 bytes for each short data type
float y1 = 3.452 // 1011,1012,1013,1014 4 bytes for float data type
cout << &y1;
&y1 is 1011
6) float s1 = 3.2; // 1015,1016,1017,1018 4 bytes for float data type
short x1 = 3, x2 = 5; //1019 1020 for x1, 1021,1022 for x2 as 2 bytes are required for short data type
int x3 = 2456; // 1023,1024,1025,1026 for x3
cout << &x1 << endl << &x3;
&x1 = 1019 and &x3 = 1023
8)
float val1 = 7.34;
short val2 = 487;
cout << &val1 << endl << &val2;
Related Questions
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.