2, simple comparison of the size of the program

Source: Internet
Author: User
Tags bitwise time 0

One, the code
1 //input A, B; output a larger value; If same, output 02 3#include <stdio.h>4 5 intMaxint,int);//c when calling a function, if the called function is defined earlier, it does not need to be declared, and if the called function is defined later, it is necessary to declare6 intMain ()7 {8    intA,b,n; 9printf"Please input the num:");//printf function, the usual usage is that there is no output number, the content needs to be output directly into the quotation marks, if the output number is added, it needs to be separated by commas, the number of direct write output after theTenscanf"%d,%d", &a,&b);//% followed by the output data type, indicating the format of the output, use: scanf ("< format description string >",< variable address >), the input format to exactly follow the previous quotation marks, followed by the variable address, so the normal variable needs to add & The address that represents it Onen=Max (A, b); Aprintf"The max between%d and%d is%d", a,b,n);//escape sequences are symbolic tokens that have special meanings in programming languages - } -  the intMaxintNUM1,intnum2) - { -    if(NUM1&GT;NUM2)//three usage of If statement: if ();  if () Esle; if () else if () Else -       returnNUM1;//If (content) means to judge the authenticity of the content, 1 is true, 0 is false, so if the inside is not an expression, but a number, as long as the value is not 0 is true, run if after, if it is 0, is false, the back does not run +    Else if(NUM1&LT;NUM2)//if ( a=b) and if (a==b) Difference: if (a=1) also assigns the value of B to a, and then determine whether a is 0, is true false, if (A==B) inside is to determine the size of a and B, determine whether a is equal to B, if equals is true, not equal to is false -       returnnum2;//C language relational operator: greater than >, greater than or equal to >=, less than <, less than or equal to <=, equals = =, not equal! =; The general form of a relational expression is: An expression-relational operator expression; The value of the relational expression is true and false, denoted by "1" and "0".  +        Else                      //Logical Operations in C: Logic and &&, logic or | |, logical NON! , general form: expression logical operator expression; A       return 0;//C-bit operators: Bitwise AND &, bitwise OR |, bitwise XOR, Inverse ~, left shift <<, right Shift >>; The same or is the input both sides of the same time is 1, not at the same time 0, XOR is the input on both sides of the 1, the same time is 0; at}
View Code

Second, constant and variable

1, in the program execution process, its value does not change the amount is called constant, its value variable quantity is called the variable.

2. Constants include:

Direct constants: Integer (integer), real (real), character (need to enclose in single quotation marks)

Symbolic constants: The identifier represents a constant, the macro definition: #define identifier constant, once defined, and later in the program where all occurrences of the identifier are replaced with the constant value (the benefit is a change to the full change).

3. Variables:

Continuous assignment is not allowed in the definition, such as a=b=c=5 is illegal

Third, the number

1, binary prefix: binary prefix 0b, decimal without prefix, octal required prefix 0 (is zero, not Europe, the beginning can not be a minus), hexadecimal prefix 0x or 0X (also 0 is not Europe),

2. Real data is also known as floating-point numbers or real numbers. In the C language, the real number is only used in decimal. It has two forms: decimal decimal form and exponential form (must have decimal points to be legal).

Exponential form: A E n (A is a decimal number must have decimals, n is a decimal integer, E large lowercase can), its value is a*10n,

3, the Real type variable

The real variables are divided into: single-precision (float), double-precision (dual-type) and long double-precision (long double) class three.

Type descriptor Number of bits (bytes) valid numbers the range of the number
Float 32 (4) 6~7 10-37~1038
Double 64 (8) 15~16 10-307~10308
Long double 128 (16) 18~19 10-4931~104932

4, the real type constant does not divide the single, the double precision, all presses the double precision doubles type processing

Four, character type data

1. Character data is a character enclosed in single quotation marks, and an escape character is a special character;

2. Character variable: The type specifier of a character variable is char

3. String

A string is a sequence of characters enclosed by a pair of double quotes

V. Conversion of data types

1. Automatic conversion

Automatic conversion occurs when the volume blending operation of different data types is done automatically by the compilation system. Automatic conversions Follow these rules:

    1. If the type of the participating operands is different, it is first converted to the same type and then the operation is performed.
    2. Conversions are performed in the direction of increased data length to ensure that the accuracy is not reduced. such as int and long operation, the int is converted into a long type before the operation.
    3. All floating-point operations are performed in double-precision, even if the expression containing only float single-precision arithmetic is converted into double type and then calculated.
    4. Char and short participate in the operation, you must first convert to int type.
    5. In an assignment operation, the type of the value on the right side of the assignment number is converted to the type of the left quantity, not the same as the data type of the quantity on either side of the assignment number. If the right amount of data type is longer than the left, part of the data is lost, which reduces precision and the missing part is rounded forward.

2. Forced conversion

Both type specifiers and expressions must be enclosed in parentheses (a single variable can be without parentheses)

(type specifier) (expression)

For example:(float) a;

(int) (x+y);

Vi. operators

1, arithmetic operators: Plus +, minus-, multiply *, except/, take the remainder (must be used for integral type),

Self-added: ++i (I self-increase after 1 and then participate in other operations), I++:I participate in the operation, I value is increased by 1;

Self-reduction:--I:I after 1 to participate in other operations, I--:I participate in the operation, I the value of 1

2, simple comparison of the size of the program

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.