following is the code that i wrote:
#include <stdio.h>
int main()
        int *ptr;
        ptr = (int *)malloc(256*256*256*256-1);
        printf("Sizeof int is %d\n", sizeof(int));
        if(ptr == NULL)
                printf("Allocation failed");
                printf("Allocation succedded");
        return 1;
i ran this code on gcc complier. now the warning that i get is
try.c: In function ‘main’:
try.c:6: warning: incompatible implicit declaration of built-in function ‘malloc’
try.c:6: warning: integer overflow in expression
try.c:6: warning: integer overflow in expression

Q 1) since the sizeof (int) =4 so why integer overflow warning is being displayed???
Q 2) how can i calculate the size of the memory chunck allocated by the malloc function????
( if i write "ptr = (int *)malloc(256*256*256*256+1000);" even though, i get these warnings and get the output of the program as "Allocation succedded: )
Kindly explain why am i getting the output as mentioned above even though the value mentioned in malloc is overflowing the unsigned int range..

thanks in advance

Last edited by shabbir; 20Jul2008 at 09:16.. Reason: Code block