Few questions about C syntax

后端 未结 8 793
暖寄归人
暖寄归人 2021-01-24 02:58

I have a few questions about C syntax.

  1. ch = (char *) malloc( sizeof( char ) * strlen(src) ); What do the first brackets mean (char *) ?

8条回答
  •  盖世英雄少女心
    2021-01-24 03:32

    1. The (char ) at the beginning of the first statement is a typecast. By default malloc returns a void which should be fine to assign to a char*, but in other cases typecasting is required.

    2. You are correct single quotes should be used around charaters.

    3. Saying scanf sometimes doesn't work is a meaningless statement without example code.

提交回复
热议问题