Experiment 7 Summary

Source: Internet
Author: User

First, the knowledge point:

1. Basic types of data:

(1) Integral type

    • Short integer type
    • Integral type (int)
    • Long shaping

(2) floating-point type

    • Single-precision float (float)
    • Double-precision floating-point type (double)

(3) Character type

    • The basic representation of data is constants and variables

2. Constants and variables

(1) Constants:

    • Symbolic constants
    • Integral type constant
    • Real-type constants
    • Character-type constants
    • The type of a constant is usually determined by the writing format. Example: 123 (integer) 4.56 (real) ' A ' (character type).
    • Symbolic constants: Represents a character constant with an identifier.
    • Identifier: A valid sequence of characters identifying the name of an object is called an identifier.
    • A valid sequence of characters that identifies an object's name is called an identifier.
    • System-predefined identifiers, such as printf, Main, sin.
    • User identifiers, such as user-defined symbolic constants, variables, function names, and so on.
    • Identifiers can only consist of letters, numbers, and underscores, and the first character cannot be a number.

(2) Variables:

    • Definition and use of variables

3. Input and output of integral type data

    • printf (format control, output parameter 1, ..., output parameter n);
    • SCANF (format control, input parameter 1, ..., input parameter n);

    • Format Control Description% ...

Decimal octal hexadecimal

int%d%o%x

Long%ld%lo%LX

    • In the output format control description, you can add a width qualifier to specify the entire

      Output width of the type data, for example:%MD, specifying the output of the data

      Width (including sign bit), if the sign bit of the data is less than M, the left

      End fill space, if greater than M, according to the actual number of digits output.

4. Real constants (real numbers, floating-point numbers)

    • Representation of a real number
    • Floating-point notation: consists of positive, negative, 0-9, and decimal points, which must have a decimal point and a number at least one side before and after the decimal.

      Example: 0.123 123.4 12. .12

    • Scientific notation: consists of positive, negative, 0-9 and letter E or E, before E must have data, after which the exponent can only be an integer. Example: 6.026E-3 1.2e+10 1E-5

e5,1.2e3.0 (illegal)

    • Type of real number double

5. Input and output of real data

    • Input scanf ()
    • Float:%f or%e

Enter a single-precision floating-point number in decimal or exponential form

    • Double:%lf or%le

      Enter a double-precision floating-point number in decimal or exponential form

    • Output printf ()

      float and double use the same format control instructions

    • %f,%LF

      Output floating-point numbers in decimal form, leaving 6 decimal places

    • %e output in exponential form
    • scanf () and printf ()

      %c

      Char ch;

      scanf ("%c", &ch);

      printf ("%c", ch);

    • GetChar () and Putchar ()

      Char ch;

      ch = getchar ();

      Putchar (CH);

      Input and output one character

6. Type conversion

Mixed operations of different types of data, first converted to the same type, and then the operation.

(1) Automatic type conversion (Assignment operation)

variable = expression

    • Computes the value of the right-hand expression of an assignment operator
    • Assigns the value of the right-hand expression of the assignment operator to the variable on the left
    • Automatically converts the type of the expression on the right side of an assignment operator to the type of the left variable of the assignment number

(2) Forced type conversion

Force type conversions in general form:

(type name) expression

7. Expressions

    • Arithmetic expression: Monocular: +-+ +--

      Binocular: +-*/%

    • Assignment expression: Simple assignment = compound Assignment (+ = = *=/=%=! =)
    • Relational Expressions:> >= < <= = =! =
    • Logical expression:! && | |
    • Conditional expression? :
    • Comma-expression,
    • Other operations: sizeof

8.++,--operator

The self-increment, decrement operator increases the value of the variable by 1 or minus 1. There are 4 kinds of forms: i++, ++i, I--、--I.

The difference between i++ (i--) and ++i (-i):

After performing the self-increment (minus) operation, the value of I is added (minus) 1,

But the value of the expression is different: the value of i++ (i--) is the original value,

The value of ++i (-i) is the value after increment (minus) 1.

Attention:

(1) The self-increment operator (+ +), the decrement operator (-), can be used only for variables, not constants or expressions. (2) + + and--the combination of the direction is "from right to left." 9. Conditional expressions

Exp1? Exp2:exp3

10. Comma-expression

Expression 1, expression 2, ..., expression n

The expression 1 is evaluated first, then the expression 2,......, and the last count

Evaluates the value of the expression N and takes the value of the expression n as a comma expression

The value.

11. Other Operations

Length operator sizeof

Monocular operator, calculating the byte length of a variable or data type

12. Arrays

Definition of one or one-D arrays

⒈ Definition Method:
Type an array group name [integer constant expression];

Example: int a[10];

⒉ Description:

① array names have the same naming rules and variable names, followed by the identifier naming convention

The constant expression after the ② array name is enclosed in [].

The ③ constant expression represents the number of elements, that is, the array length.

Example: a[10] means that the array a contains 10 elements, respectively,

A[0]~A[9]

References to two or one-D array elements

The array must first be defined and then used. The C language specifies that an array element can only be referenced one at a time without referencing the entire array at once.

The reference form is:

Array name [subscript]

Initialization of three or one-D arrays

You can use an assignment statement or an input statement to get the value of an element in an array, which is performed during a program run. It is also possible to initialize an array before the program is run, that is, the initial value is obtained during compilation.

The initialization of an array element can be implemented in the following ways:

⒈ the array element is assigned an initial value when it is defined.

such as: int a[10]={0,1,2,3,4,5,6,7,8,9};

⒉ can assign values to only a subset of the elements.

such as: int a[10]={0,1,2,3,4};

Indicates that only the first 5 elements are assigned an initial value, and the last 5 elements are automatically assigned 0 values.

⒊ does not assign an initial value to the static array, the system automatically assigns 0 values to all elements.

That is, if you want to make the value of all elements in array a 0, you can define an array like this:

static int a[5];

⒋ the array length can be specified without assigning an initial value to all array elements.

int a[5]={1,2,3,4,5};

int a[]={1,2,3,4,5};

Definition of four or two-d arrays

Type descriptor array name [constant expression] [constant expression]

Example: float a[3][4],b[5][10];

Description

① can think of a two-dimensional array as a special one-dimensional array.

A[0]→a[0][0] a[0][1] a[0][2] a[0][3]

A[1]→a[1][0] a[1][1] a[1][2] a[1][3]

A[2]→a[2][0] a[2][1] a[2][2] a[2][3]

② Two-dimensional arrays are stored in memory by rows.

③ multidimensional arrays are defined in a way similar to a two-dimensional array

int x[3][4][2];

float y[4][2][3];

References to five or two-d arrays

The reference form is: array name [subscript] [subscript]

Note: The subscript can be an integer expression, but should be in the defined array size

In the range.

Initialization of six or two-D arrays

⒈ Branch assigns an initial value to a two-dimensional array. Such as:

int a[3][4]={{1,2,3,4},{5,6,7,8},{9,10,11,12}};

⒉ can write all of the data in curly brackets, assigning an initial value to each element in the order in which they are arranged.

int a[3][4]={1,2,3,4,5,6,7,8,9,10,11,12}

⒊ can assign an initial value to some elements, not 0. Such as:

int A[3][4]={{1},{5},{9}}

int a[3][4]={{1},{0,6},{0,0,11}};

⒋ If you assign an initial value to all elements, the length of the first dimension can be unspecified when you define the array, but the length of the second dimension cannot be saved.

int a[3][3]={1,0,3,4,0,0,0,8,0}

int a[][3]={1,0,3,4,0,0,0,8,0}

int a[][3]={{1,0,3},{4,0,0},{0,8,0}}

Second, the problems encountered in the experiment and solutions:

This experiment is mainly to write the last experiment content into a menu, you need to copy the previous code body part of the line, can always appear error.

Workaround: Copy the function body part into the case, declare the function at the top, and define the function at the bottom.

Third, the experimental experience:

Modeled after the teacher in the course of writing the menu process to write this homework, originally thought it would be relatively simple, can be practical to find there is still an omission of the place

Experiment 7 Summary

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.