Adobe Interview Question
Computer ScientistsThis is mine , which is faster? a or b ?
This can be asked to cache performance issue
int **allocate(int row,int col)
{
int b[2][3]={};
int **a=(int**)malloc(row*sizeof(int*));
for(int i=0;i<row;i++)
{
a[i]=(int*)malloc(sizeof(int)*col);
}
for(int i=0;i<row;i++)
for(int j=0;j<col;j++)
{
a[i][j]=i;
}
return a;
}
- Anonymous June 15, 2011