c ++ basic knowledge

  In C, & has several meanings
  
  1. When the two are connected together. &&. Represents the meaning of "和"
  
  For example, a == 1 && b == 2. It is when a = 1 and b = 2!
  
  2. Denote a reference, such as int a; int & ra = a; // define the reference ra, which is a reference to the variable a, namely the alias
  
  3, & represents two operators, one of which represents the value operator and one is Bitwise AND
  
  (3.1), value operator
  
  int a = 1;
  
  int * p = & a; // where & a means to take out the address in a, and then assign it to the pointer variable, which means & a means The address of variable a in memory. You can use the printf function to output this address
  
  (3.2), bitwise and operator
  
  calculation rules: if both numbers are true (or 1), the result is true, if one of the two digits is false (or 0) If the result is false
  
  such as a & b; means to perform binary bitwise AND operation of a and b
  
  such as 8 & 10, where the binary of 8 is 0000 1000, and the binary of 10 is 0000 1010, so
  
  0000 1000 (decimal 8)
  
  & 0000 1010 (decimal 10)
  
  results in 0000 1000 (that is, decimal 8)
  
  so 8 & 10 results in 8
  
  =================== <c ++ basic knowledge &> =======================================
  
  ---------------------------------- <|| Operator from left to right, truncate judgment> --- -------------------------------------------------
  
  / /coutTEst.cpp: defines the entry point of the console application.
  
  //
  
  #include "stdafx.h"
  
  #include "iostream"
  
  using namespace std;
  
  int _tmain (int argc, _TCHAR * argv [])
  
  {
  
  int a = 0;
  
  int b = 0;
  
  if (((a = 3) | | (b = 3)))
  
  {
  
  a ++;
  
  b ++;
  
  }
  
  cout << a << endl;
  
  cout << b << endl;
  
  return 0;
  
  }
  
  // The output result is 4, 1
  
  ======== ================ <|| Operator from left to right, truncation judgment> ===================== ========
  
  ------------------------------------------ <&& operator from left to right, all judged>
  
  // coutTEst.cpp: defines the entry point of the console application.
  
  //
  
  #include "stdafx.h"
  
  #include "iostream"
  
  using namespace std;
  
  int _tmain (int argc, _TCHAR * argv [])
  
  {
  
  int a = 0;
  
  int b = 0;
  
  if (((a = 3) && (b = 3)))
  
  {
  
  a ++;
  
  b ++;
  
  }
  
  cout << a << endl;
  
  cout << b << endl;
  
  return 0;
  
  }
  
  ================= =========== <&& operator from left to right, all judgement> =========================== =========
  
  c ++ basic knowledge supplement, code fans, mamicode.com
  
  c ++ basic knowledge supplement

Guess you like

Origin www.cnblogs.com/zhenhua1618/p/12729404.html