C Programming - Memory Allocation - Discussion
Discussion Forum : Memory Allocation - Find Output of Program (Q.No. 5)
5.
Assume integer is 2 bytes wide. How many bytes will be allocated for the following code?
#include<stdio.h>
#include<stdlib.h>
#define MAXROW 3
#define MAXCOL 4
int main()
{
int (*p)[MAXCOL];
p = (int (*) [MAXCOL])malloc(MAXROW *sizeof(*p));
return 0;
}
Discussion:
21 comments Page 3 of 3.
Mohini said:
1 decade ago
Here why is sizeof(*p) taken as 2,but not 4*2=8?.
no no i think viraj is not correct,
and we are taking sizeof(*p) as 8 and then multiplying it with 3 to get 24
no no i think viraj is not correct,
and we are taking sizeof(*p) as 8 and then multiplying it with 3 to get 24
Post your comments here:
Quick links
Quantitative Aptitude
Verbal (English)
Reasoning
Programming
Interview
Placement Papers