用C两个变量(如+++ B)之间3加号 [英] 3 plus symbols between two variables (like a+++b) in C

查看:120
本文介绍了用C两个变量(如+++ B)之间3加号的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

 的#include<&stdio.h中GT;诠释的main()
{
    int类型的= 8,B = 9,C;
    C = A +++ B:
    的printf(%d个%D \\ n,A,B,C);
    返回0;
}

以上输出的节目 A = 9 B = 9 C = 17 。在 A +++ b 为什么编译器会 A ++ ,然后用补充b 。为什么不采取 A +
++ b ?是否有一个特定的名字为这个 A +++ b 。请帮我明白了。


解决方案

我喜欢 C专家编程:


  

ANSI标准规定,已经到了被称为公约
  在最大适合的策略。最大蒙克说,如果有更多的
  以上的可能性为下一个标记,编译器将preFER到
  咬掉所述一个涉及的最长序列。所以
  例如将被解析

  C = A + + + B;


#include <stdio.h>

int main()
{
    int a=8,b=9,c;
    c=a+++b;
    printf("%d%d%d\n",a,b,c);
    return 0;
}

The program above outputs a=9 b=9 and c=17. In a+++b why is the compiler takes a++ and then adds with b. Why is it not taking a + and ++b? Is there a specific name for this a+++b. Please help me to understand.

解决方案

I like the explanation from Expert C Programming:

The ANSI standard specifies a convention that has come to be known as the maximal munch strategy. Maximal munch says that if there's more than one possibility for the next token, the compiler will prefer to bite off the one involving the longest sequence of characters. So the example will be parsed

c = a++ + b;

这篇关于用C两个变量(如+++ B)之间3加号的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆