Home  >  Q&A  >  body text

c++ - 求教各位大神关于VS2010与c-free,putchar函数与puts函数的问题

代码如下

#include<stdio.h>

int main(void)
{
    putchar('\0');
    return 0;
}

求教各位大神,为什么结果会那么奇怪?我私下试过了,为什么putchar('0')会显示a呢?就这一点很奇怪,其他的都正常,请问大神,难道是我的运行库出问题了?本人小白,研究了2天都没想明白,求高人

伊谢尔伦伊谢尔伦2765 days ago701

reply all(3)I'll reply

  • PHP中文网

    PHP中文网2017-04-17 15:25:22

    It should be a problem with your environment. I tested it on dev c++ and it worked fine

    reply
    0
  • 高洛峰

    高洛峰2017-04-17 15:25:22

    I have no problem in my compiler (gcc (GCC) 4.4.7 20120313 (Red Hat 4.4.7-4)). Is the code in your screenshot putchar('0'); or putchar("0") ;?

    reply
    0
  • 大家讲道理

    大家讲道理2017-04-17 15:25:22

    putchar outputs a character, puts outputs a string, encounter

    The parameter in putchar must use single quotes '0'. If you use double quotes "0", the compiler will randomly output a character

    reply
    0
  • Cancelreply