Procedural programming teaching

        The basic design of the underlying data type during programming


Outline

Data types can be said that a language is the most basic part, even if the basic data are not well understood clearly, then the written procedures must also reach a very high standard.

Classification and presentation of data types

The basic data classification

The data points to the actual type




  • Integer : Integer, by definition it can be understood as an integer, as to why there will be short, int, long three, due to the size of the data they store the decision.

  • Floating point : floating-point, indicating that it has a decimal point, so it can be understood as the difference between the decimal, floating-point single-precision and double precision floating point is that the number of decimal places, the higher the accuracy, the more the number of decimal digits .

  • Character : character, which is used to store the characters, like A, B, C , etc. This is the type of character data, but as char such a word can not be used to store the character type, the character string belonging to type data.

Notes : This blog is intended to explain the most basic data types, pay attention to an entry like structures, pointers, arrays of these types require some programming after understanding more convenient to understand, not explained in this blog in.


Use according to points

constant

basic concepts

1. the name suggests is a constant amount can not be changed during program execution.
2. The constant value can not be modified after being defined.

classification
  • Integer constant
  • Real constant (floating point format)
  • Character constant
  • ..........

variable

basic concepts

1. variables during program execution may vary.

2. The variables must first be defined before use

类型关键字 变量名;
int a;(举例)

Examples of the basic variable declarations

#include<stdio.h>

int main(){
    int a;//声明一个整型变量
    a=1;
    float b;//声明一个浮点型
    b=2.5;
    char c;//声明一个字符变量
    c='A';
    printf("%d %f %c",a,b,c);
    return 0;
} 

operation result


3. Expresses its character naming rules


  • It must be made by letter or an underscore ( ) as the beginning

  • Which can be followed by any letters, numbers or underscores)

  • Case-sensitive

  • You can not use keywords as identifiers


_________________________________________________________________________

Cast

Data cast a beginner the most easy to fall into the pit, but also the most easily overlooked aspect of beginners

For example:

It is a problem, for example to calculate the temperature

error examples

#include<stdio.h>

int main(){
    int i=45;
    double h = (i-32)*5/9;
    printf("温度为:%4.1f",h);
    return 0;   
} 


The purpose of this question is to convert Fahrenheit to Celsius, but the results are not running the show.

Examples of correct

#include<stdio.h>

int main(){
    int i=45;
    double h =(double) (i-32)*5/9;//唯一不同之处,强制转换的作用地
    printf("温度为:%4.1f",h);
    return 0;   
} 

Cast, which means that the data type cast to the type of data I need.
In the present example i is an int data, after the latter is calculated or derived data type int type, but we need is double type data, it is necessary to cast type.



I am limited, if wrong, welcomed the guidance.

Guess you like

Origin www.cnblogs.com/tianbatua112/p/11516721.html