& Lt; 1 & gt; very happy on the first day of blog creation! Just write a little simple, then the data type, constants and operators (C language), new operators

Source: Internet
Author: User

<1> on the first day of blog creation, I am very happy! Just write a little simple, then the data type, constants and operators (C language), new operators

[Data type]
1 --- bool

  • # Include <stdbool. h> (header files specific to the bool type)
  • The boolean type has only two values: 0 and 1.

2 --- char

  • 1 byte, 8 bits

3 --- int occupies 4 bytes

  • Short occupies 2 bytes
  • Long occupies 4 bytes

4 --- float occupies 4 bytes (float type is decimal type, such as 12.34)

  • Double occupies 8 bytes

5 --- default void type (to put it bluntly, it is an empty type)

[Constant]
1 ---- integer constant

  • Decimal: 23
  • Octal: 023
  • Hexadecimal: 0x23

2 ---- floating point Constants

  • Example: 12.34

3 ---- exponential constant

  • 12.3e-3 => 12.3*10 ^ 3

4 ---- character constant (the character is enclosed by a pair of single quotes)

  • 'A 'B' \ n' \ 0' '9'

5 ---- String constant (the string is enclosed in a pair of double quotation marks)

  • "A": 'A' \ 0'
  • "Hello": 'H' 'E' E' l 'l' o ''\ 0'
  • The character string defaults to 0, which is '\ 0'. Therefore, the string "A" contains two characters: 'A' and' \ 0 '.

6 ---- macro definition

  • # Define N 12
  • Macro definition: In my understanding, it is generally to define the data -----> that is, you do not need to change the number of its values when using it.
  • For example, you define an integer type array int a [N];
  • Then, if you want to change its space to 64, you can define # define N 64

[Operator] (I don't think it's good to remember it by force. Remember it when you use it)

1 ---- Arithmetic Operators

  • +-*/% + + --

2 ---- Relational operators

  • <<=>>==! =
  • The result of the relational operation is in either of the following States: 0 1

3 ---- logical operations

  • &: The operation represents a false value.
  • |: Or indicates true.
  • ! : False or false.

The result of the logical operation is only in two states: 0 1
Short-circuit principle: When an expression can determine the result of the entire expression, the following expression does not operate.

4 ---- bitwise operation (mostly used for unsigned integer operations)

  • &: Bitwise AND, false
  • |: Bit or, true
  • ~ : Reverse, true or false, false or true
  • ^: Returns an exclusive or. The same value is 0. The difference is 1.
  • >>: X> n <=> x/2 ^ n
  • <: X <n <=> x * 2 ^ n

5 ---- compound Operators

  • + =-= * =/= % =
  • ^ = & = | = <=> =

Data exchange:

  • A ^ = B;
  • B ^ =;
  • A ^ = B;

6 ---- conditional Operators

  • <Expression 1>? <Expression 2>: <expression 3>;
  • First Judge expression 1. If it is true, execute expression 2. If it is false, execute expression 3;

7 ----, (comma)

  • Lowest priority

8 ---- forced type conversion

  • Conversion between similar data types.

9 ---- sizeof

In fact, I personally think this is a very important function.

  • For example:
  • Evaluate the size of the Data opening space
  • For example, you define an array int a [] = {1, 2, 3, 4, 5, 6, 7, 8}. Suppose there are many elements in the array, you need to know the size of a and you will have sizeof ();
  • Or you want to know the sizeof (int) Size of an int type );

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.