The basic syntax.

  1. The basic data types common space (64-bit machine, for example)

    •  char: 1 byte
    •  int: 4 bytes
    •  float: 4 bytes
    •  double: 8 bytes

    Basic types of writing

    <p an integer>
    •  a, default is 10 decimal, 10, 20.
    •  b, beginning with 0 as octal, 045,021.
    •  c., beginning with 0b as binary, 0b11101101.
    •  d, beginning with 0x hexadecimal, 0x21458adf.

    Decimal

    Single-precision constants: 2.3f.

    Double constant: 2.3, the default double precision.

    Character constants

    Enclosed in single quotation marks, save only the character 'a', 'b', '*', as well as the escape character '\ n', '\ t'.

    String constant

    English double quotation marks can be saved due to multiple characters: "abc".

    1, data type conversion: C if a language expression contains different types of constants and variables in the calculation, they will be automatically converted to the same type; may be cast data types in the C language;

    2, automatic conversion rules:

    (  A) floating-point number is assigned to an integer, the decimal floating-point numbers are discarded;

    (  B) float from integer, the same value, but is stored in the corresponding floating-point variables;

    3, cast in the form:  (type specifier) (expression)

  2. Examples of program:

    #include<stdio.h>
    
    int main() {     float f,x=3.6,y=5.2;     int i=4,a,b;     a=x+y;     b=(int)(x+y);     f=10/i;     printf("a=%d,b=%d,f=%f,x=%f\n",a,b,f,x); }

    In the first embodiment was 8.8 x + y is calculated, and then assigned to a, since a is an integer, the integer part Pickup 8, a = 8;

    Next, the b x + y is an integer cast;

    Finally, 10 / i is an integer of two division, the result remains an integer of 2, the floating-point number is assigned to F 2;

    x is a floating-point output directly.

Guess you like

Origin www.cnblogs.com/zhangdemingQ/p/12111663.html