ios-(4) data type, constants, variables

Source: Internet
Author: User

First, the data

1. What Is Data

* Life is always with data, such as weight data, blood pressure data, stock price data and so on. In our use of computer process, will be exposed to a variety of data, there are document data, image data, video data, as well as chat QQ generated text data, with thunder download file data.

2. Classification of data

* Data stored in computer can be divided into two types: static data and Dynamic Data.

* Static data

# concept: Static data refers to some permanent data, generally stored in the hard disk, hard disk storage space is generally relatively large, now ordinary computer hard disk has about 500G, so the hard disk can be stored in some relatively large files.

# The length of storage: After the computer is turned on, the data is still in, as long as you do not actively delete or the hard drive is not bad, the data will always be.

# Those are static data: Static data is usually stored on the hard disk in the form of files, such as documents, photos, videos, etc.

* Dynamic Data (temporary data)

# concept: Dynamic Data refers to temporary data that is generated dynamically during the course of a program's operation, typically stored in memory. Memory storage space is generally small, now normal computer memory as long as about 4G, so use memory carefully, do not occupy too much memory space.

# Length of storage: After the computer shuts down, the temporary data will be erased.

# which is Dynamic Data: When running a program (software), the entire program will be loaded into memory, in the process of running the program, will produce a variety of temporary data, these temporary data are stored in memory. When the program stops running or the computer is forced to shut down, all temporary data generated by the program will be erased.

You might ask, why not load all the applications on the hard drive, since the hard disk storage is so large? One of the main reasons is that the memory accesses faster than the hard disk n times.

What data does the programmer care about the most?

* Conversion of static and dynamic Data

# Static dynamic hard disk (Jjj.mp4)-Turn-memory (Storm Video)

# dynamic--Static Internet--memory (Thunderbolt)--HDD (JJJ.MP4)

3. Size of the data

* Both static and dynamic data are composed of 0 and 1. 0 and 1 if it makes up so much data?

* Data are size, static data will occupy hard disk space, Dynamic Data will occupy memory space.

* The larger the data, the more the 0 and 1 are included, bits and bytes

* 1kb = 1024b, 1MB = 1024kb, 1G =1024MB,1TB = 1024GB

All kinds of data in 4.app

* Game score, chat history, news, etc.

Data types in the 5.C language

Due to the wide variety of data in the app, C-language data is classified to facilitate the operation of data.

* NULL type: void

* Pointer type: void*

* Construction Type: Array, struct (struct), Union (Common), enum (enum)

* Basic Data type: Int (integer), char (character type), float float (single-precision floating) double (double-precision floating-point).

Second, constant

1. What is a constant

* constants, which represent some fixed data

2. Classification of constants

* Integral type constant (int)

# contains all the integers, such as 6, 27, 108,-190, 278, etc.

* Floating-point constant (float\double)

Floating-point constants are divided into double and float two types

# double: dual-precision floating point, in fact, is a decimal. such as 5.43,-2.3, 0.0 (note, 0.0 is a decimal)

# float: single-precision floating-point type, also a decimal, is less accurate than a double, meaning it can represent fewer decimal places. To differentiate from double, the float type data is terminated with F, such as 5.4f, -2.3f, 0.0f. It should be noted that there is absolutely no 10f such format, the compiler will directly error, only decimals allowed to add F.

* Character Constants (char)

# Match a number (0~9), English letter (a~z, a~z) or other (+ 、-、! 、? And so on) are enclosed in single quotation marks, which make up a character constant. such as ' 6 ', ' A ', ' F ', ' + ', ' $ ' and so on.

Note: The single quotation mark can only enclose 1 characters, and cannot be Chinese characters, the following wording is wrong: ' abc ', ' 123356 ', ' Male '.

* String Constants

# enclose one or more characters in double quotation marks (""), which makes up a string constant. such as "6", "Male", "wow haha", "JDJJL", "My_car3", in fact printf ("Hello World"), the statement "Hello World" is a string.

Third, variable

1. What is a variable

* When the value of a data needs to change frequently or is not sure, it should be represented by a variable. Some points, for example.

2. Defining variables

* Purpose

# Before any variables can be used, they must be defined first.

# The purpose of defining variables is to allocate a piece of storage space in memory to variables, which makes it easy to store data later.

# If more than one variable is defined, a different storage space is allocated for the multiple variables.

* Format

# variable type variable ming;

such as int num;

# Variables belong to identifiers

# variable Type

# Different types of variables occupy different sizes of storage space. The memory is extremely limited, allocating the appropriate storage space.

# The type of data that the constraint variable holds (convenient operation)

* Example

int main ()

{

int i; char c; int A, B; return 0;

}

3. Use of variables

* Assign Value

# to store something in a variable is to assign a value. With a semicolon after the assignment statement;

i = 10;

Note: The equals sign here is not "equal" in mathematics, but the assignment in C, which assigns the right constant 10 to the left variable i.

# The first assignment can be called initialization.

# Two types of initialization

-Define first, then initialize: int A; A = 10;

-Define simultaneous initialization: int a = 10;

* Modify

# You can modify the value of a variable and assign it multiple times. Each assignment will overwrite the original value.

i = 10;

i = 20;

The last value of the variable is 20;

# Use printf () to output the value of one \ Multiple variables

int a = ten, c=11

printf ("a=%d,d=%d", a,c);

#double \float\char output, some tips for formatting characters

Double height = 1.55;

char blood = ' A ';

printf ("height =%2f, blood type is%c", Height,blood);

# Simple Add-minus operation

int a = 10 +20;

# do not use when not initialized (the following wording is not recommended)

int score;

printf ("Score =%d", score);

* Transfer of values between variables

# You can assign a variable's value to another variable

int a = 10;

int b = A;

# Continuous Assignment

A = b = 10;

4. Common errors

* Variable name is the same as int a = 10; int a = 12;

* Variable scope is not correct

# The process of creating and releasing variables

# Scope of code block {int a = 10;}

      

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.