#include <stdio.h>
typedef unsigned short u32;
int main()
{
u32 *ptr = NULL;
u32 *ptr1 = NULL;
u32 temp;
int i;
ptr = malloc(512);
if( ptr == NULL) {
printf("memory allocation failed\n");
exit(1);
}
for(i=0 ; i< 512; i++){
ptr[i] = 0;
}
for(i=0 ; i< 512; i++){
printf("%d", ptr[i]);
}
temp = (u32)ptr;
ptr1 = (u32 *)temp;
for(i=0 ; i< 512; i++){
printf("%d", ptr1[i]);
}
return 0;
}
when I compiled it with gcc, I got some warning
eg.c:29: warning: cast from pointer to integer of different size eg.c:30: warning: cast to pointer from integer of different size
when I executed the code, it gave me segmentation fault...
can anyone tell me what is wrong with this code...


Sign In
Create Account


Back to top









