behaviour of malloc(0)

后端 未结 3 2067
旧巷少年郎
旧巷少年郎 2020-11-30 13:48
int main()
{
    char *p;
    p = (char* ) malloc(sizeof(char) * 0);
    printf(\"Hello Enter the data without spaces :\\n\");
    scanf(\"%s\",p);
    printf(\"The          


        
3条回答
  •  温柔的废话
    2020-11-30 14:47

    In addition to Als comment - what happens: you write somewhere into memory and retrieve the data from there. So depending of your system and OS type you get a exception or just some undefined behaviour

提交回复
热议问题