繁体   English   中英

为什么printf不在控制台上打印“ operator”?

[英]Why printf does not print “operator” on console?

底部printf()不会在控制台上打印运算符变量。 但是仅打印number1number2 可能是什么原因?

输出:2 7是多少?

char operator;

    switch(type){   
        case 1: 
        operator=='+';
        result=number1+number2;
        break;
        case 2: operator=='-';
        result=number1-number2;
        break;
        case 3: operator=='*';
        result=number1*number2;
        break;
        case 4: 
        operator=='/';
        result=number1/number2;
        break;

    }       
    printf("How much is %d %c %d ?",number1, operator, number2);
operator=='+';

应该

operator='+';

其他运营商也一样

c中的赋值仅带有=

相等的比较与==示例if(operator == '+')

==是相等运算符,它不分配值只是检查两边是否相等。

您必须使用赋值运算符=

例如:

operator='/'

而不是使用赋值运算符= ,而是使用比较运算符 ==

因此,之后operator=='+'的价值operator保持不变。

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM