Monday, January 16, 2012

Coding Puzzle No. 13?

#include<stdio.h> 
 
void main()
{
   int s[3];
   int *p = (int *)malloc(sizeof(int)*4);
   printf("\n%d %d",sizeof(s),sizeof(p));
}
  
 Output:
 12 4
 

ConCept(tested in gcc complier): 
We cannot use pointer to get the size of memory allocated. Using size of operatoron pointer will return size of pointer.

No comments:

Post a Comment