C Programming Language (two)

Chapter C data types

Octal integer number of 0 at the beginning, followed by a sequence of numbers consisting of 0 to 7.

The letters hexadecimal integer x (or X) at the beginning, followed by the numbers 0 to 9, 0, a ~ f (or A ~ F) in a sequence of numbers.

 

Integer constants:

  • Is defined as the default type int signed integer, so the type without using signed int
  • Unsigned integer constant: U
  • Long integer constant: L
  • Unsigned long integer constant: LU

 

Decimal form

Exponential form: 3.45e-6 = 0.00000345

 

Real constants:

  • Single-precision: F
  • Double precision (real constant default)
  • Long double precision: L

 

Variables must be defined before use, you need to type the variable name and variable declarations.

 

// L2-1a-1

main () // in main () as the starting point C designates the beginning of a program executed 
// a C program must have one and only one with a main () function as a name, called main function { 
    int    A; 
    a float B;             
    char  C;  A. 1 = ;  B = 2.5 ; C = 'A' ;}

 

  • Variable names (identifiers) are case sensitive
  • All variables must be defined before the first executable statement
  • Space program is to enhance the readability
  • Definitions of the variables can be simultaneously initialized variables, such as int a = 1;

 

// L2-1a-2

main () 
{ 
    int a =. 1; / * define integer variables and initializes a * / 
    a float b = 2.5; / * define a real variable b and initializes * /         
    char C = 'A'; / * define c string variables and initializes * /         
}

 

The same can also define a plurality of variables, such as int a, b, c;

Comments can not be nested!

 

// L2-1b

#include <stdio.h> // This is the C preprocessor command 
// This line will appear in each of the data required from the output to the screen or keyboard input program data main () 
{ 
    int = A. 1 ; 
    a float = 2.5 B ;             
    char C = 'a' ;  // \ n-output represents a newline  printf ( "a =% d \ n", a); / * output by the integer format value of a variable * /  the printf ( "B =% f \ n ", b ); / * output by the format real value of the variable b, unless specified otherwise implied decimal output 6 * / the printf ("% C = C \ n-", C); / char * format by the output variable value of c * / the printf ( "End of Program \ n-"); / * output line of the string * / }
// Run Results 
A. 1 = 
B = 2.500000 
C = A 
End of Program

 

Variable data type or the size of the space occupied:

  • 1B (byte) = 8bit
  • sizeof () keyword is the C language, not a function name
  • the sizeof () is a C language specially provided for calculating the number of bytes of the specified data type operator

 

// L2-2

#include  <stdio.h>
main()
{
    printf("Data type        Number of bytes\n");
    printf("------------  ---------------------\n");
    printf("char                    %d\n", sizeof(char));
    printf("int                     %d\n", sizeof(int));
    printf("short int               %d\n", sizeof(short)); printf("long int %d\n", sizeof(long)); printf("float %d\n", sizeof(float)); printf("double %d\n", sizeof(double)); }
Results // Run
 the Data bytes of type Number The 
----------------------- --------------------- 
char. 1 
int. 4 
Short int 2 
Long . 4 int 
a float. 4 
Double. 8

 

Assignment expressions are used to assign values ​​to variables

  • Directional
  • Left of the equal sign is the variable name can represent a particular unit of storage

 

Priority of the operations

  • Comprehensive: left-associative, right associative
  • C language requires two operands in arithmetic operators are left-associative
  • Assignment operator is right-associative

 

Signed integer and unsigned integers

  • For integer has the same number of words, the absolute value of the largest integer signed integer only half the non-signed integer
  • Negative numbers in a computer are based on two's-complement form to represent and store
  • Positive anti-code complement its original code is the same

 

  • 'S complement subtraction can be converted to the adding process to
  • S complement can be represented in a uniform manner and +0 -0

 

Exponent part real number called the exponent, referred to as the fractional part of the mantissa

  • Exponent bits occupied by the real number determined table range, determines the number of bits occupied by the mantissa accuracy of real numbers
  • Mantissa sign determines the sign of the real number

 

The real number of floating-point numbers is not really, but its approximate within a certain range

 

// L2-3

#include <stdio.h>
main()
{
    float   a;
    double     b;
    a = 123456.789e4;
    b = 123456.789e4;
    printf("%f\n%f\n",a,b); }
// operating results 
1234567936.000000 
1234567890.000000

Guess you like

Origin www.cnblogs.com/dingdangsunny/p/11371654.html