We use cookies to ensure you have the best browsing experience on our website. Please read our cookie policy for more information about how we use cookies.
Hi, I'm fairly new to coding and don't really understand the concept of allocating memory. I just have a quick question - I was wondering why we had to allocate memory for the queries? My code looks similar to yours, except I only have 1 array:
#include<iostream> usingnamespacestd;intmain(){int**a;// create dynamic arrayintn,q;// number of rows, number of queriescin>>n>>q;a=newint*[n];for(introw=0;row<n+1;row++){//go thru each row to enter variable length of col intk;cin>>k;// # of columns for specific rowa[row]=newint[k];for(intcol=0;col<k+1;col++){// fill each column for specific rowcin>>a[row][col];}}for(intcount=0;count<q+1;count++){//fulfill queriesintrow;intcol;cin>>row>>col;cout<<a[row][col];}return0;}
Cookie support is required to access HackerRank
Seems like cookies are disabled on this browser, please enable them to open this website
Variable Sized Arrays
You are viewing a single comment's thread. Return to all comments →
Hi, I'm fairly new to coding and don't really understand the concept of allocating memory. I just have a quick question - I was wondering why we had to allocate memory for the queries? My code looks similar to yours, except I only have 1 array: