Meaning of "+ +" operator (not ++)

This question already has an answer here:

  • Several unary operators in C and C++ 3 answers
  • What is the “-->” operator in C++? 21 answers
  • Unary plus (+) against literal string 1 answer

  • There is no + + operator. There's a + operator (which occurs in both unary and binary forms), and a ++ operator, not used here.

    Each of those is a binary + operator followed by one or more unary + operators.

    This:

    c = c + + "d";
    

    is equivalent to

    c = c + (+ "d");
    

    This:

    c = c + + + "d";
    

    is equivalent to:

    c = c + (+ + "d");
    

    or:

    c = c + (+ (+ "d"));
    

    And so forth.


    The first + is a binary plus which calculates the sum of c and the second term.

    The remaining + are unary plus operators. In + "d" , "d" is of type const char[2] , and decays to const char* . Then + is applied to the pointer which has no effect, and returns the same const char* .

    c + + + "d" is equivalent to c + (+(+"d")) .


    这只是很多一元加号。

    链接地址: http://www.djcxy.com/p/1976.html

    上一篇: 为什么没有“<”

    下一篇: “+ +”运算符的含义(不是++)