What does “:=” do?

前端 未结 10 1558
别那么骄傲
别那么骄傲 2020-12-04 10:47

I\'ve seen := used in several code samples, but never with an accompanying explanation. It\'s not exactly possible to google its use without knowing the proper

相关标签:
10条回答
  • 2020-12-04 11:16

    http://en.wikipedia.org/wiki/Equals_sign#In_computer_programming

    In computer programming languages, the equals sign typically denotes either a boolean operator to test equality of values (e.g. as in Pascal or Eiffel), which is consistent with the symbol's usage in mathematics, or an assignment operator (e.g. as in C-like languages). Languages making the former choice often use a colon-equals (:=) or ≔ to denote their assignment operator. Languages making the latter choice often use a double equals sign (==) to denote their boolean equality operator.

    Note: I found this by searching for colon equals operator

    0 讨论(0)
  • 2020-12-04 11:23

    Colon-equals was used in Algol and its descendants such as Pascal and Ada because it is as close as ASCII gets to a left-arrow symbol.

    The strange convention of using equals for assignment and double-equals for comparison was started with the C language.

    In Prolog, there is no distinction between assignment and the equality test.

    0 讨论(0)
  • 2020-12-04 11:24

    It's the assignment operator in Pascal and is often used in proofs and pseudo-code. It's the same thing as = in C-dialect languages.

    Historically, computer science papers used = for equality comparisons and for assignments. Pascal used := to stand in for the hard-to-type left arrow. C went a different direction and instead decided on the = and == operators.

    0 讨论(0)
  • 2020-12-04 11:24

    In a lot of CS books, it's used as the assignment operator, to differentiate from the equality operator =. In a lot of high level languages, though, assignment is = and equality is ==.

    0 讨论(0)
提交回复
热议问题