Question

In: Computer Science

Draw a memory layout to show the relations of a, b and c. char a[3][10] =...

Draw a memory layout to show the relations of a, b and c.

char a[3][10] = {"abcdefg", "1234567", "!@#$%^&"};
char* b[3];
char** c;
b[0] = &a[0][0];
b[1] = &a[1][0];
b[2] = &a[2][0];
c = b;
char x = b[0][3];
char y = b[0][13];

Solutions

Expert Solution

Solution

Let's assume array a is stored starting from memory location 100.

Assuming each caracter occupies 1 byte and a pointer occupies 8 bytes.

The three elements of array b are the pointers, which store address of element a[0][0], a[1][0] and a[2][0] respectively.

c stores the starting address of array b.

The memory layout for better understanding is shown below:

char x = b[0][3];

b[0][3] = *(*(b+0)+3)

* represent the value at operator.

*(b+0) = b[0] = 100

b[0][3] = *(*(b+0)+3) = *(100+3) = Value stored at memory location 103 = Character 'c'

char y = b[0][13];

b[0][13] = *(*(b+0)+13)

* represent the value at operator.

*(b+0) = b[0] = 100

b[0][13] = *(*(b+0)+13) = *(100+13) = Value stored at memory location 113 = 4


Related Solutions

for C program 10 by 10 char array. char 0-9 as rows and char a-j as...
for C program 10 by 10 char array. char 0-9 as rows and char a-j as collumns.
7. Subway restaurants closely represent a a. Product layout b. Fixed layout c. Continuous layout d....
7. Subway restaurants closely represent a a. Product layout b. Fixed layout c. Continuous layout d. Process layout . 8. The process of assigning the activities to various workstations such that the total idle time of each workstation is minimized is a. Productivity improvement b. Man-machine interaction c. Capacity planning d. Line balancing e. Flag this question . 9. An automobile paint shop will benefit the most with a. Continuous layout b. Fixed layout c. Process layout d. Product layout...
6- Write a C++ program that determines the amount of memory used by char, short int,...
6- Write a C++ program that determines the amount of memory used by char, short int, unsigned short int, float, and double types and display the information on the screen. You program should also display the typical range for each data type.
Write in C programming language Write the function replace(char b[], char f[], char t[]). which finds...
Write in C programming language Write the function replace(char b[], char f[], char t[]). which finds the string 'f' in the string 'b' and replaces it with the string 't'. You can assume that f and t same length Example: char string[] = "zap";     replace(string, "ap", "oo"); --changes 'string' to "zoo".     *don't assume substring being replaced is singular, or that its own substrings are unique.     *Don't re scan letters already checked and replaced         char string[] =...
Draw the main memory diagram as captured at the end of the C program
FOR C PROGRAMMING LANGUAGE Draw the main memory diagram as captured at the end of the C program (i.e. return 0; statement). Your diagram must clearly shows where str, p1, p2, and p3 are pointing to, when the program terminates. int main(void) { char str[] = "cs111 NYU"; char* p1 = str; p1 ++; char** p2 = &p1; char* p3 = &str[4]; printf("1. str = %s\n", p1); if(p3 - p1 == 4) { printf("2. p1 == p3\n"); } printf("3. char1...
Determine the memory address of A[3], A[10], A[20] a) given int A[] b) given short A[]...
Determine the memory address of A[3], A[10], A[20] a) given int A[] b) given short A[] c) given char A[]
If I show (A and (B → C)) → D and (A and (C → B))...
If I show (A and (B → C)) → D and (A and (C → B)) → D, can I conclude A → D?
Draw a graph The US has 10% inflation and 3% unemployment. Apply Monetary Policies Show the...
Draw a graph The US has 10% inflation and 3% unemployment. Apply Monetary Policies Show the application of the policies on the following, in this order: Production Possibilities Curve (before = the situation, after = policies applied) Money Market (as the policies are applied) Loanable Funds (as the policies are applied) Investment Demand (as the policies are applied) Aggregate Model (before = the situation, after = policies applied)
Consider this set A = { a, b, c, d } and the following relations R6...
Consider this set A = { a, b, c, d } and the following relations R6 = { ( a, a ), ( a, b), ( b, b), ( c, d ) } R7 = { ( a, a), ( b, b ), ( b, c ), ( c, c ), ( c, d), (d, d) } R8 = { (a, b), (a, d), ( b, a), ( d, a) , ( b, d) , (d, b) } R9 =...
a.) Draw the structural formula of (E)-1,2-dibromo-3-isopropyl-2-hexene b.) Draw the structural formula of (Z)-3-methyl-2-heptene. c.) Draw...
a.) Draw the structural formula of (E)-1,2-dibromo-3-isopropyl-2-hexene b.) Draw the structural formula of (Z)-3-methyl-2-heptene. c.) Draw the structure for 1-chloro-3-hexyne d.) Draw the structure for cyclooctyne e.) Draw the structure for 4,4-dimethyl-1-pentyne
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT