Skip to content
Ben Shen edited this page Mar 12, 2019 · 12 revisions

Additional note

  • short-circuit

    • INCLUDING Logical AND operator &&, Logical OR operator ||, Conditional operator ?
  • For class iteration_statement

    • constructor for both While and Do While are BOTH Expression FIRST, then statement
  • Scope for for,while loop ref

    • As is the case with while loop, if statement is a single statement (not a compound statement), the scope of variables declared in it is limited to the loop body as if it was a compound statement.
    for (;;)
        int n;
    // n out of scope
    • While in C++, the scope of the init-statement and the scope of statement are one and the same, in C the scope of statement is nested within the scope of init-statement:
      for (int i = 0; ; ) {
          long i = 1;   // valid C, invalid C++
          // ...
      }
  • type cast are RIGHT_associative (its actaully implemetation defined)

    unsigned char x= 255;
    std::cout << (int)x << "!\n"; // unsigned char ->  unsigned int -> int (NOT SURE, default case), return 255
    std::cout << (int)(signed char)x << "!\n"; unsigned char -> char -> int, return -1

ISO/IEC 9899:TC3 6.3.1.4
As discussed earlier, whether a ‘plain’ char is treated as signed is implementation-defined

  • function declaration vs prototype ref
    • A non-prototype declaration does not say anything about parameters.
    • Prototype is a declaration that describes the number and the types of function parameters.
    int foo(); //declaration, It means that foo take an __unspecified number of arguments__
    int foo(void); //prototype 
    int foo(int a, double b); //prototype
    int foo(int, double); //prototype
Clone this wiki locally