Char arrays and scanf function in C

后端 未结 4 1768
春和景丽
春和景丽 2021-01-13 17:49

I expected to get errors in following code, but I did not. I did not use & sign. Also I am editing array of chars.

#include <         


        
4条回答
  •  孤城傲影
    2021-01-13 18:22

    #include 
    #include 
    
    int main(int argc, char **argv, char **envp) {
        char *myName = (char *) calloc(10, sizeof(char));
        *(myName)='K'; *(myName+1)='h'; *(myName+2)='a'; *(myName+3)='l'; *(myName+4)='i'; *(myName+5)='d';
        printf("%s\n",myName);
        scanf("%s",myName);
        printf("%s\n",myName);
        return (EXIT_SUCCESS);
    }
    

提交回复
热议问题