assigning more than one character in char

后端 未结 2 512
伪装坚强ぢ
伪装坚强ぢ 2020-12-09 14:29

Why this program gives output \'y\'

#include 

int main(void) {
    char ch=\'abcdefghijklmnopqrstuvwxy\';
    printf(\"%c\",ch);         


        
2条回答
  •  半阙折子戏
    2020-12-09 15:03

    If you intended to print out abcdefghijklmnopqrstuvwxy, then you should have stored it into a string variable instead of a char one (char ch[50] = char abcdefghijklmnopqrstuvwxy;).

    String variables can hold more than one character, where as a char variable is for holding one character.

提交回复
热议问题