C语言中的常量与运算符是什么?
摘要:Constants Constants are expressions with a fixed value. Literals Literals are the most obvious kind of constants. They a
目录ConstantsLiteralsInteger NumeralsFloating Point NumeralsCharacter and string literalsOther literalsTyped constant expressionsPreprocessor definitions (#define)define identifier replacementOperatorsAssignment operator (=)Arithmetic operators ( +, -, *, /, % )Compound assignment (+=, -=, *=, /=, %=, >>=, <<=, &=, ^=, |=)Increment and decrement (++, --)Relational and comparison operators ( ==, !=, >, <, >=, <= )Logical operators ( !, &&, || )Conditional ternary operator ( ? )Comma operator ( , )Bitwise operators ( &, |, ^, ~, <<, >> )Explicit type casting operatorsizeofOther operatorsPrecedence of operatorsReferences
Constants
Constants are expressions with a fixed value.
Literals
Literals are the most obvious kind of constants. They are used to express particular values within the source code of a program. We have already used some in previous chapters to give specific values to variables or to express messages we wanted our programs to print out, for example, when we wrote:
a = 5;
The 5 in this piece of code was a literal constant.
Literal constants can be classified into: integer, floating-point, characters, strings, Boolean, pointers, and user-defined literals.
Integer Numerals
1776
707
-273
These are numerical constants that identify integer values. Notice that they are not enclosed in quotes or any other special character; they are a simple succession of digits representing a whole number in decimal base; for example, 1776 always represents the value one thousand seven hundred seventy-six.
In addition to decimal numbers (those that most of us use every day), C++ allows the use of octal numbers (base 8) and hexadecimal numbers (base 16) as literal constants. For octal literals, the digits are preceded with a 0 (zero) character. And for hexadecimal, they are preceded by the characters 0x (zero, x). For example, the following literal constants are all equivalent to each other:
75 // decimal
0113
