Question: In C: Assume an array has been declared as float arr [ 2 0 ] [ 8 ] ; What value of m can be

In C:
Assume an array has been declared as
float arr[20][8];
What value of m can be used so the following is true?
(float*)arr +m==&(arr[12][2])
(i.e., arr [12][2] is m floats ahead of arr in memory)
Note: you will lose 10% for each incorrect submission.
Answer:
Your Submission
Rating
Sub-Subject
Topic
C Programming Language
Passing Arrays To Functions
Step-by-step
Step 1 of 3
To find the value of m in,
1(float)arr+m==&(arr[12][2]),
we need to understand the memory layout of a 2D array.
In C, a 2D array is stored in a contiguous block of memory. The address of arr[0][0] is the same as the address of arr[0][1]+sizeof(float), Rows? v? neea to skip 1 rows (Irom inaex to |)1), and each row is 8 floats. So,12**8=96 floats.
Columns: We need to skip 2 columns (from index 0 to 1) in the 12th row, which is an additional 2 floats.
So,m=96+2=98.
Explanation:
Therefore, the correct answer is m=98.
 In C: Assume an array has been declared as float arr[20][8];

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!