+ 1

I m nt able to understand this code can anyone help me

Major doubt is why len =60 why??? https://code.sololearn.com/c82KM7rLeVSo/?ref=app

27th Feb 2020, 9:51 AM
Manito
5 ответов
+ 2
bluesea i know how it came 60, i wanted to know why we want len=60 and whole program explaination Thanx for the response
27th Feb 2020, 10:24 AM
Manito
+ 2
Your code contains error. You can allocate less memory than you use: you store pointers to row, but size calculate as for indexes of rows in line#6 instead of len=sizeof(int)*r+sizeof(int)*r*c sholud be len=sizeof(int*)*r+sizeof(int)*r*c len can be 60 or 72 depending on platform, but in your code it is always 60 (assuming that sizeof(int) = 4) c is num of cols r is num of rows arr is used to store matrix. it consists of 2 parts. part#1 is array of pointers to each row of the matrix. its size = sizeof(int*)*r. part#2 is matrix itself. its size = sizeof(int)*r*c len is the total size = size of part#1 + size of part#2 = sizeof(int*)*r+sizeof(int)*r*c r = 3, c = 4 matrix contains 3*4=12 cells. size of each cell = sizeof(int) = 4 matrix size = 12 * 4 = 48 - it is size of part#2 space for storing 3 pointers to each row = sizeof(int*) * 3 = 12 (for 32bit platform or 24 for 64 bit machine) - it is size of part#1 len = 60 or 72 depending on platfrom. 1st loop is used to setup row pointers (part#1) 2nd loop is used to initialize a matrix to sequence of numbers 3rd loop prints matrix
27th Feb 2020, 10:28 AM
andriy kan
andriy kan - avatar
+ 1
andriy kan--> thank u so much, your explanation is awesome 🙌🙌nice one
27th Feb 2020, 10:54 AM
Manito
+ 1
@Manito, You are welcome
27th Feb 2020, 10:56 AM
andriy kan
andriy kan - avatar
0
See this it may help you to understand. https://code.sololearn.com/cp80iLJaiNhx/?ref=app
29th Feb 2020, 12:52 PM
Rafik Abdelhak Nadir
Rafik Abdelhak Nadir - avatar