Dark Horse programmer _ first day video learning

Source: Internet
Author: User
Tags variable scope

 

 

I. computer and software knowledge

1. Computer Operating Principle

1) basic hardware components: hard disk, memory, CPU

2) coordination of various components ()

2. Computers can only recognize 0 and 1

1) commands composed of 0 and 1

2) data composed of 0 and 1

3. Connection between computers and software

1) Basic Concept of software: Set of commands

2) install and run the software

3) Why develop software: write commands that can control computers

4. Computer Language

1) a language that deals with computers

2) easy to write a series of commands

Ii. Computer Language Development History

1. Machine language

1) Introduction: There are only 0 and 1 in all codes. Each Command is called a "machine command"

2) Advantages

The code can be directly recognized by the computer, directly acting on the hardware, and the execution efficiency of the program is very high.

Allows you to directly access and control various computer hardware devices, such as disks, memory, CPU, and I/O Ports.

3) Disadvantages

The program is full of Code commands ranging from 0 to 1, with poor readability and error-prone.

The hardware is highly dependent, so the machine languages of different types of computers are different. That is to say, if two machines of different models want to implement the same function, you need to write two sets of completely different codes.

It is difficult to remember the meaning of all the commands and commands on the computers used.

4) usage scenarios

To sum up, machine language is difficult to grasp and promote. Nowadays, in addition to the professional staff of computer manufacturers, most programmers no longer want to learn machine language.

2. Assembly Language

1) Introduction: replace machine commands with English words and other symbols

2) Advantages

Like machine languages, you can directly access and control various computer hardware devices.

Low memory usage and fast execution

3) Disadvantages

Different machines have different assembly language syntaxes and compilers, and the Code lacks portability. That is to say, a program can only run on one machine and cannot run on another machine.

There are many symbols and hard to remember. Even a simple function requires a lot of assembly language code, which can easily generate bugs and make debugging difficult.

Must have a good understanding of hardware, low development efficiency, long cycle and monotonous

4) usage scenarios

Operating system kernel, driver, Single Chip Microcomputer Program

Software Encryption, decryption, and cracking

Virus production and Prevention

Program debugging and Analysis

3. Advanced Language

1) Introduction: close to natural language

2) Advantages

Simple, easy to use, easy to understand, syntax and structure similar to Common English

Keep away from direct hardware operations, so that ordinary people can program after learning, rather than getting familiar with hardware knowledge.

A program can also run on different machines, with portability

3) Disadvantages

The program cannot be directly recognized by the computer. It must be translated into binary commands by the compiler before it can run on the computer.

4) types: C language, C ++, C #, Java, and objective-C

Iii. Introduction to C language 1. A Brief History

1) C language was invented in 1972 and used for the first time to rewrite the Uinx Operating System (Unix was mainly written in assembly language before and laid the foundation of the operating system)

2) with the success of the UNIX operating system, the C language has also been widely used on large, medium, small, and micro hosts, it is one of the most popular and widely used advanced programming languages in the world.

3) C language is a process-oriented, non-object-oriented language.

2. Features

1) rich Operators

2) rich data types

3) You can directly operate the hardware.

4) efficient target code

5) Good portability

3. Main use

1) Write System Software, graphic processing, Single Chip Microcomputer Program, Embedded System Development

2) Compile game plug-ins

3) Compile the android Program

4) Write iOS programs

......

4. Version Problems

1) in 1983, the American National Standards Institute (ANSI) established a committee to develop C language standards.

2) the C language standard was approved in 1989. The C language standard of this version is usually called ANSI C

3) in October 1999, ISO revised the C language standard. On the basis of retaining the features of the original C language, some functions were added to meet the requirements and named c99.

4) on October 13, December 8, 2011, ISO officially announced the C language's new draft international standard: C11

Iv. coding 1. Program Structure

1) first C program structure: composed of functions

Any C language program is composed of one or more program segments (applets), each of which has its own functions. We generally call these segments "functions ". Therefore, you can say that the C language program is composed of functions.

2) Basic concepts of functions

Function Name: A program consists of countless functions. Each function has its own name.

Call (execute) a function: You can call the corresponding function based on the function name to execute the corresponding function.

3) C program entry

The entry to the C program is a function called Main.

No matter how many functions exist in the program, the main function is executed first.

2. Write a program

1) Compile the main function (the content in braces {} is the function body)

int main(){    return 0;}

2) write multiple functions and call them.

int test(){    return 0;} int main(){    test();    return 0;}

3) use the printf function to output content to the screen.

#include <stdio.h>int main(){    printf("Hello World!");    return 0;}
V. Compilation

1) What is Compilation: translate the C source program into a computer that can recognize 0 and 1

2) What compiler is used: xcode3 uses GCC and xcode4 uses llvm Compiler (Clang is used at the front end)

3) How to Use the clang compiler to compile programs?

Enter the CC-C file name in the terminal. c

After compilation is successful, the. O target file is generated.

4) compiler errors and warnings

If the Code has Syntax problems, the compiler will directly report an error. The number of errors and the specific row number are also specified.

As long as there is one error, the program cannot be compiled successfully, and the. o file will not be generated.

Warning information is only some suggestions of the compiler and does not affect Compilation

6. Links

1) Functions of the link: combines the. o file and the C language function library to generate executable files

2) completed by the linker. The clang compiler already contains the link instruction.

Enter: CC file name. O in the terminal

A. out executable file is generated after the link is successfully linked.

VII. Run

1) Two running Modes

Double-click to open the. Out file.

Use the./A. out command in the terminal

2) After modifying the file content, you must re-compile and link the file before running it.

3) \ n function: Press enter to wrap

8. Other clang commands

Modify the executable file name: cc xxx. O-o file name

Compilation and link: cc xxx. c

 

9. Common Errors for beginners

Do not write a semicolon or use a Chinese semicolon

Double quotation marks are missing for strings, or single quotation marks are used. Double quotation marks are contained in double quotation marks.

The code is not written in the main function, before return

The extension name of a file is not.

Use an absolute path to compile the file. Pay attention to the location where the target file is generated.

10. Summary

1) the entire program running process

 

2) summarize the extended names of common files

. C is a C-language source file, which is created during code writing.

. O is the target file, which is generated when compilation is successful.

. Out is an executable file generated when the link is successful.

3) Summary of clang commands

Compile: CC-c xxx. c

Link: cc xxx. o

Compilation and link: cc xxx. c

Run the executable file:./A. Out

4) What errors will be encountered during development? How can this problem be solved?

U syntax error, which can be solved through the error message of the Compiler

U logic error. You need to debug the program with patience

5) Learning suggestions

Learning programming is not learning English.

Program readability

Do not seek root questions for beginners

11. Exercise

Output the following pattern using two different code methods

************

** Itcast **

************

Code 1:

#include <stdio.h>int main(){    printf("************\n");    printf("** itcast **\n");    printf("************\n");    return 0;}

Code 2:

#include <stdio.h>int main(){    printf("************\n** itcast **\n************\n");    return 0;}
12. Keywords 1. What is a keyword?

1> keywords are symbols with special meanings provided by the C language, also known as "Reserved Words"

2> A total of 32 keywords are provided in C language. These keywords are given special meanings by C language.

Auto double int struct break else long switch

Case Enum register typedef char extern return Union

Const float short unsigned continue for signed void

Default goto sizeof volatile do if while static

You can simply browse it over again without having to go to the functions of every keyword of Baidu. These keywords will be frequently used in the future, and it will be hard for you to remember them.

2. Keyword features

1> all are in lower case

2> special colors are displayed in development tools or smart text editing tools. By default, all keywords in the C language are purple-brown in xcode.

3. What are keywords in the main function?

Int, return

13. identifier 1. What is an identifier

Identifiers are some of the symbols and names customized in the program. To distinguish it from keywords: keywords are the symbols provided by C language by default, and identifiers are customized by programmers.

 

2. Functions of identifiers

1) identifiers. Literally, They are symbols used to identify something. They are used to distinguish them.

2) In fact, the role of an identifier is similar to that of a human name. To distinguish each person, a name is given at the time of birth.

3) C language is composed of functions. a c program may have multiple functions. to distinguish these functions, each function is named. The function name is a type of identifier. In addition to functions, we will also learn the concept of "variables". The variable name is also an identifier.

 

3. Name

1> naming rules (must comply)

L can only contain 26 English letters, 10 Arabic numerals, 0 ~ 9. Underline _

L strictly case sensitive. For example, test and test are two different identifiers.

L cannot start with a number

L you cannot use keywords as identifiers.

 

2> naming conventions (preferably observed)

L try to create a meaningful name, such as a complete English word. Only when someone else looks at the name can this identifier be used. If you do not understand English, you can also use Pinyin. Try not to use meaningless names such as ABCDE and sfsdfsdf.

L if the identifier contains multiple words, you can use the camper mark (except for the first word, the first letter of each word is capitalized): firstname, myfirstname, or use underscore _ to connect: first_name, my_first_name

 

4. common identifier naming errors

Legal identifier

Invalid identifier

Note

Fromno12

From #12

The # symbol cannot be used in the identifier.

My_boolean

My-Boolean

The "-" symbol cannot be used in the identifier. The underscore "_" should be used instead.

Obj2

2 ndobj

The identifier cannot start with a number.

Myint

Int

"Int" is a built-in keyword.

Jack_rose

Jack & Rose

The symbol "&" cannot appear in the identifier

Gui

G.u. I

The "." separator must appear inside the identifier.

 

14. Note 1. What is a comment?

1) annotation is a very important concept in all computer languages. Literally, it refers to the meaning of annotation and interpretation.

2) annotations can be used to explain the meaning of a program or a line of code to facilitate communication between programmers. If I add the corresponding comments after writing a line of code, then when someone else sees this comment, they will know what the code is.

3) Comments can be any text, that is, Chinese characters can be written.

4) in development tools, the comment is generally bean paste green

 

2. Single Row comment

1) A single line comment starts with two forward slashes, and starts with //. Only one line can be commented. From // to the end of this line, all comments are comments.

2) Comments can be written anywhere: Outside the function, inside it, after each statement

 

3. Multi-line comment

Multi-line comments start with/* and end with */. The content in the middle of/* and */is both comments.

 

4. Functions of annotations

1> the annotated code does not participate in compilation.

Annotations are intended for users rather than computers. How Can computers view the Chinese we write. Therefore, when the program is compiled, the comments are not compiled into the. O target file.

From the size of the. o file, we can indirectly see that the annotated code is not compiled.

2> check the function of the Code

3> troubleshooting

 

5. annotation nesting

1) single-row comments can be nested with single-row comments and multi-row comments

// Wow Haha // heh/// * fsdfsdf * // sdfsdfsd

2) multi-line comments can be nested with single-line comments

/* // Mj // Description: The first C Language Program: This is a main function, the entry point of the C program */

3) multi-line comments cannot be nested with multi-line comments

/* Hahaha/* giggle */Heh */

4) The following statements are incorrect.

/// * Hahaha */
6. Importance of annotations
Develop a good habit of writing comments. The first thing for most project managers to check their subordinate codes is to see if they have written comments. Many companies also try to check comments. (A computer test is to give you a programming question and a computer, solve the problem within the specified time)
Today, you have written several hundred lines of code. I'm glad that you have made a very good function. However, you forgot to write comments. After a week, you may not be able to understand the code. This is a normal task. If you write comments, the situation will be different. Comments can help you review the role of the Code.
You have been in a company for more than a year and have written tens of thousands of lines of code, but you do not need to write any comments. One day, when you leave your job and a new employee takes over your project, he must first understand the code you wrote. However, you did not write any comments at all. The 0.1 million lines of code are all in English, which makes this new employee very painful. Everyone has their own ideas. The idea of writing code is definitely different. It is very painful to read the code written by others, especially the code without comments. If you do not write comments, the company's development efficiency will be greatly reduced. Therefore, all formal companies place great importance on annotations.
7. Exercise

Check whether the following program runs successfully. If yes, the running result is displayed:

1> program 1

// Main function int main () {printf ("itcast \ n"); Return 0 ;}

Running result: itcast

 

2> Procedure 2

// Main function int main () {printf ("// itcast \ n"); Return 0 ;}

Running result: itcast

 

3> Program 3

Main function int main () {printf ("itcast \ n"); Return 0 ;}

Cannot run results

4> Procedure 4

int main(){    printf(//"itcast\n");    return 0;}

Cannot run results

5> program 5

Int main () // main function {// printf ("itcast \ n"); Return 0 ;}

Cannot run results

 

15. Data 1. What is data?

We are always dealing with data, such as weight data, blood pressure data, and stock price data. When we use computers, we will be exposed to a variety of data, including document data, image data, and video data, there are also text data generated during chatting on QQ, and file data downloaded by thunder.

2. Data Classification

Data stored in a computer can be divided into static data and dynamic data.

1> static data

Concept: static data refers to some permanent data, which is generally stored on hard disks. Hard disk storage space is generally relatively large, and now the hard disks of ordinary computers are about GB, so the hard disk can store some relatively large files.

Storage Duration: After the computer is turned off, the data is still on. As long as you do not actively delete the data or the hard disk is not broken, the data will always be there.

Static Data: static data is generally stored on hard disks as files, such as documents, photos, and videos.

 

2> dynamic data (temporary data)

Concept: Dynamic Data refers to the temporary data dynamically generated during the running of the program, which is generally stored in the memory. The memory storage space is usually relatively small. Currently, the memory of a general computer is only about 4 GB. Therefore, use the memory with caution and avoid occupying too much memory space.

Storage Duration: After the computer is disabled, the temporary data is cleared.

Dynamic Data: when a program (software) is run, the entire program is loaded into the memory, and various temporary data is generated during the program running, the temporary data is stored in the memory. When the program stops running or the computer is forced to shut down, all temporary data generated by the program will be cleared.

You may ask: Since the storage space on the hard disk is so large, why not load all applications into the hard disk for execution? The main reason is that the access speed of the memory is n times faster than that of the hard disk.

What data do programmers care about most?

 

3> conversion of static and dynamic data

4. Data size

1) Both static and dynamic data are composed of 0 and 1. How does 0 and 1 make up so much data?

2) If all data has size, static data will occupy the hard disk space, and dynamic data will occupy the memory space.

3) The larger the data, the more 0 and 1 contained, the bit and byte

4) 1 kb = 1024 B, 1 MB = 1024 kb, 1 GB = 1024 MB, 1 TB = 1024 GB

5. Data Types in C Language

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

16. Constant 1. What is a constant?

Constant, indicating some fixed data

 

2. Constant Classification

1> integer constant (INT)

Contains all integers, such as 6, 27, 109, 256,-10, 0, and-289.

 

2> float type constant (float \ Double)

Float constants are classified into double and float data types.

Double: Double float type, which is actually decimal. For example, 5.43,-2.3, and 0.0 (note that 0.0 is a decimal number)

Float: Single-precision floating point type, which is also a decimal point, which is less accurate than double, that is, it can represent less decimal places. To distinguish it from double, float data ends with F, such as 5.43f,-2.3f, and 0.0f. Note that the 10f format is absolutely not supported. the compiler will directly report an error and only allow F to be added to decimal places.

 

3> character constant (char)

Convert a number (0 ~ 9), English letters (~ Z, ~ Z) or other symbols (+ ,-,! ,? And so on. For example, '6', 'A', 'F', '+', and '$.

Note: single quotes can only contain 1 character and cannot contain Chinese characters. The following statements are incorrect: 'abc', '123', and 'mal'

 

4> string constants

Enclose one or more characters in double quotation marks ("") to form a String constant. For example, "6", "male", "Wow haha", "ABCD", and "my_car4", in fact, printf ("Hello World"); "Hello World" in the statement is a String constant.

17. Variable 1. What is a variable?

When the value of a data item needs to be changed frequently or uncertain, It should be represented by a variable. For example, game points.

 

2. Define Variables

1> Purpose

Any variables must be defined before use.

The purpose of defining a variable is to allocate a storage space to the variable in the memory to facilitate future data storage.

If multiple variables are defined, different buckets are allocated for these variables.

2> Format

Variable name;

For example, int num;

L variable name is an identifier

L variable type

U variables of different types occupy different sizes of storage space. Memory is extremely limited and proper storage space is allocated

The data type of the U constraint variable (easy operation)

3> instance

int main() {     int i;char c;int a, b;     return 0;    }
3. Use of Variables

1> value assignment

Save something to the variable, that is, assign values. Assign a value with a semicolon;

I = 10;

Note: The equal sign = here is not equal in mathematics, but the value assignment operator in C. It is used to assign the constant 10 on the right to the variable I on the left.

The first assignment, which can be called "initialization"

Two initialization Modes

First defined, then initialized: int A; A = 10;

Initialize the definition at the same time: int A = 10;

2> modify

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

I = 10;

I = 20;

The last value of variable I is 20.

Use printf to output the value of one or more variables

Int A = 10, c = 11;

Printf ("A = % d, c = % d", a, c );

Double \ float \ char output, some tips for formatting characters

Double Height = 1.55;

Char blood = 'a ';

Printf ("Height = %. 2f, blood type: % C", height, blood );

Simple addition and subtraction

Int A = 10 + 20;

Do not use it when Initialization is not performed (the following statement is not recommended)

Int score;

Printf ("score = % d", score );

3> passing values between variables

You can assign a value to another variable.

Int A = 10;

Int B =;

L continuous assignment

A = B = 10;

 

4. Common Errors

1> the variable name is the same as int A = 10; int A = 12;

2> the variable scope is incorrect.

Variable creation and release process

Code block scope {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.