Data, basic data types, constants, and variables

Source: Internet
Author: User

First, the data

Picture text and so on are data, stored in the computer with 0 and 1.

  1. Classification

Data is divided into static data and dynamic Data.

(1) static data: Some permanent data, generally stored in the hard disk, as long as the hard disk is not bad data are present. Usually stored in the form of files on the hard disk, the computer shutdown after the restart still exists.

(2) Dynamic Data: In the process of running the program, the dynamic temporary data generated, generally stored in memory, memory storage space is generally small, the computer shuts down after the data will be erased. The temporary data will be erased if the software or computer shuts down.

(3) static data and dynamic data can be converted.

Note: Why not store dynamic data on the hard drive? Because the speed of direct access to memory is faster. The software is installed on the hard disk and runs in memory. Programmers should be more concerned with memory data.

  2. Data size

(1) All data are made up of 0 and 1.

(2) data are size, static data account for hard disk space, Dynamic Data account for memory space.

(3) The larger the data, the more 0 and 1 are included,

(4) The units in which the data is stored are bits and bytes. A 1 or 0 is a bit, that is, 1bit.

(5) The data is stored in bytes on the computer. 1 bytes = 8 bits (1byte=8bit).

(6) 1tb=1024gb,1gb=1024mb,1mb=1024kb,1kb=1024b.

Ii. Types of data

C has a rich data type, so it is well suited for writing databases, such as DB2 and Oracle, written in C.

The data types of the C language can be broadly divided into the following categories:

Three, constant

1. Definition: Constants represent fixed data.

  2. Classification

(1) Integral type constants such as 6,27,-299

(2) floating-point constants such as 5.43,-2.3,5.67f

(3) Character constants such as ' 6 ', ' A ', ' F ' (not Chinese as ' male ')

(4) string constants such as "6", "Male", "NANABC"

Iv. variables

 1. As with other languages, the C language uses variables to store the values used by the calculation process, and any variable must first define the type and then use it. Why must we define it first? Because the type of the variable determines the storage space that the variable occupies, the variable type is defined to allocate the appropriate storage space for the variable to hold the data. For example, if you are a char type, I will only allocate 1 bytes to you, it is not necessary to allocate 2 bytes, 3 bytes or more storage space.

2. In C, when you declare a local variable, you can use it without initializing the assignment.

#include <stdio.h>int  main () {    int  b;               printf ("%d", b);     return 0 ;}

But this is very dangerous and is not recommended. Most people should think that variable B should be 0, not really. Because the system will randomly assign a value to the variable B, the resulting garbage data.

The printed result of the above code is: Therefore, the local variable must be initialized before the assignment, and then use, this is the safest way.

Note: if the INT type variable is global, the system assigns a value of 0 by default

  

 The range of 3.char is: ASCII character or -128~127 integer

(1) using char to store capital letters A has 2 ways to assign values:

// Mode 1 Char ' A ' ; // Mode 2 Char ;

The above two methods are equivalent because the ASCII value of capital A is exactly 65.

(2) Char can store only one character

Chinese characters or strings need to be stored in an array of characters, because one character occupies 2 characters, and a string is made up of one or more characters.

Therefore, the following syntax is wrong:

Char ' I'm ' ; Char ' 123 ' ; Char " 123 ";

V. Type modifiers

  1. We can also add some modifiers to the base data type, and some call it the qualifier, the same meaning.

The following 4 types of modifiers are available:

(1) Short type

(2) long type

(3) signed signed type

(4) unsigned unsigned type

  2. These modifiers are most often used to modify the int type (you can omit int)

//the following two types of notation are equivalent Short intS1 =1; ShortS2 =1;//the following two types of notation are equivalentLong intL1 =2;LongL2 =2;//continuous use of 2 longLong LongLL =Ten;//the following two types of notation are equivalentSignedintSI1 =3; signed Si2=3;//the following two types of notation are equivalentUnsignedintUS1 =4; unsigned US2=4;//you can also use 2 modifiers at the same timeSigned Short intSS =5; unsignedLong intUL =5;

 3.short and long can provide different lengths of integer number, that is, you can change the range of integers, such as the value range of short -32768~32767,long is the value range is -2147483648~2147483647

4. Of course, the storage length of the data will change as well. For example, in a 64-bit compiler environment, short accounts for 2 bytes (16 bits), int accounts for 4 bytes (32 bits), and long takes 8 bytes (64 bits). There are many compilers in the world, different compiler environments, the range of values and the length of occupation is not the same, but fortunately, the ANSI \ ISO set the following rules:

    (1) Short and int at least 16 bits (2 bytes)

(2) Long is at least 32 bits (4 bytes)

(3) The length of short can not be greater than the length of int,int is not greater than long

(4) Char must be 8 bits (1 bytes), after all, char is the smallest data type we can program

  5.signed and unsigned

(1) signed represents unsigned, including positive, negative, and 0;unsigned for unsigned, only positive and 0. For example, the value range of signed is -32768~32767, then the unsigned range is 0~65535, of course, different compilers have different range of values

(2) In fact, the difference between signed and unsigned is whether their highest bit is to be used as the sign bit, and does not change the length of the data as short and long, that is, the number of bytes.

  6.signed, unsigned can also be modified Char,long can also be modified double

Char Ten  char c2 =-ten; Long Double 12.0;

Vi. storage lengths for basic data types in different compiler environments

Red represents a common data type

Data, basic data types, constants, and variables

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.