Getting started with dummies programming (c)

Source: Internet
Author: User

Some people want to take the C language computer level 2 and have no basic programming skills. I will record the QQ accounts and continue to talk about the unfinished things. I hope it will save effort to do similar work in the future. For senior programmers with years of programming experience, these are really little dishes. In addition, in order to cope with the second-level examination, strictly speaking, it cannot be considered a true basic computer explanation.

But in fact, I think the Foundation should be the most difficult. Which of the following is not the most important and difficult part of a computer? For a person without a programming Foundation, if he wants to get started with programming quickly, he can only instill it in a very stupid way. He can only say a lot of things very simple and dead, or even an error. If not, how can we get started quickly? I think that I learned the C language from the teacher's mouth, but it was just a dumb's understanding. The solution to the problem is mostly hard to remember. The computer world has its own logic. for a beginner, it takes a long time for you to understand the computer logic, until one day this logic goes deep into the bone marrow.

(The following shall be done with caution)

When you are new to programming, you think that the memory is a big square, and your program is randomly placed in it. Later I learned that the operating system has virtual memory management, virtual address translation to physical address, page ing, memory swap, function stack space, and global storage space, there are also heap that can be dynamically applied for release, and even the storage area of the dynamic link library. In these processes, hardware is even directly involved, such as virtual address translation.

When programming for beginners, I thought that the program compiled on the ugly interface of Turbo C exclusively enjoyed the CPU resources, and thought that the program is the execution entity in the computer. We do not know that the operating system has processes and threads. These execution entities share computer resources and run on the same CPU or the same core of the same CPU in a time-based manner.

As for the algorithm and data structure, it is not so difficult to understand. It is not so surprising that after you understand it, you will be amazed that "my previous understanding is so naive. Although the design of algorithms and data structures is very laborious, we need to constantly refine the correctness, efficiency, implementation details, and availability...

All serial items on the CPU and operating system will be overturned to a large extent when the GPU is reached. However, with the upgrade of GPU hardware and the development of the GPU programming environment, programming on the SPMD processor will become as convenient and easy as using vs GCC on the CPU, there is no need to consider too much hardware details.

There are more things to talk about. Let's get started. Let's talk about the rough concept first. We can talk about the details in more time. It is more like a Learning Guide. We still need to read a book to really understand it. In addition, moxiao is the most basic and dumbest.

1. Computer Basics

Computer, that is, computer. Why are you using it all day ??
A: He is running the program.
CPU is an electronic device that executes programs. It executes programs to complete various tasks. What is a program ?? Programs can generally be understood as a series of execution commands. These commands are written by you, and the computer completes the work according to your instructions. C language is such a program. The source files of the program written in C Language (usually end with. C ). Processing through a computer program (this is calledCompilerYou don't understand what it is, but you have to use it at least) to generate executable files and run them on your computer. Therefore, generally, the process of writing a program in C language is:
1. Write source code
2. generate executable files through compiler Compilation
3. Run the command to check whether the program you wrote is correct.
Step 3 is also called the debugging program. Test whether your program has any errors by yourself. The simplest way is to execute it and see if it works as you think.
So if you want to learn the C language, you must write the program, use the compiler, and then debug it.
Let's talk about debugging this later. This is a long-term accumulated experience on how to debug quickly.

Memory, hard disk, keyboard, display, CPU, is the computer hardware that you must access when writing C language programs. Next we will introduce these hardware one by one.

Memory and hard disk are both stored. What is the difference between them ??
Your laptop has hard disks and memory. Generally, the memory is several GB, 1 GB to 4 GB. The hard disk is dozens to hundreds of GB. The hard disk is used for long-term storage. Hard Disk data will not be lost after the power-off of the computer, and the memory is temporarily stored. As soon as the computer is powered off, the memory data will be gone. So you usually store things in the hard disk, which will occupy the hard disk space.
So what is the memory used ??? In this case, hard disk access is slow, and memory access is fast. Therefore, in computer programs, memory is generally used. Because you need to complete a computing task, you do not need to wait until the computer is powered off. For example, if you want to create a calculator, add, subtract, multiply, and divide it, then you can see the result, without the need for long-term storage. The data is stored in the memory.
So most computer programs are dealing with memory, and the C language program is also.

So I learned about the memory and hard disk, and what the CPU, keyboard, and display are doing.
CPU is the execution of operations, but you do not need to worry about writing programs.
The display displays the results of your program and your input.
The keyboard is used for input.
Basically, you need to take the second-level exam. Sometimes it will let you read files and write files, so this is the operation of the hard disk, remember that the files are stored in the hard disk.

2 C language basics

C language is the originator of all modern popular languages. To learn about it, you must understand some of its basic concepts:

Variable
Variable type
Variable definition
Operator
Sequential execution
Conditional execution (if else)
Loop execution (for, while)
Function
Array
Structure
Pointer

Variable

A variable is a part of the memory space that stores the data you need During computation. You can read it, write data to it, or perform operations on it. Therefore, variables may be the most important and basic concept, which is closely linked to the memory. However, you don't need to always think about memory when learning to write programs.
What are the elements of a variable ??
A: variable type, variable name.
The variable type can indicate its operation. The behavior of this variable occupies the memory size. Variable names are used to differentiate variables and operate and reference them.
For example:
Int;
This is an integer variable named.
The type of the variable determines whether you can operate on it and the behavior of the operation. For example, if int is an integer, positive and negative int can be the abbreviation of an English integer. Unsigned Int Is an unsigned integer of the 0 and positive integers. Float is a floating point number, which can be considered as a decimal number.
Different types of variables may have different actions for the same operation. For example, a-B.
For integer a and B, the result is an integer.
For an unsigned integer, that is, a and B of a positive integer, the result is an unsigned integer, but it may also be an invalid value, because if B is greater than, the result may be meaningless.
As for floating point numbers, and so on.
In short, one of the purposes of computer operations is to determine the type of operation numbers and the type of operation results. If two calculation types are different or the types required by the calculation numbers and operators are different, the computer will convert them to you.

Operator

Now we have talked about arithmetic operations, so we can go to the next topic, that is, operators. A variable is a basic concept and an operator. The computer is doing operations all day long, and operators are signs of these operations.
There are two main types of operators: arithmetic operation and logical operation. As for bitwise operations, I don't know whether to take the test. Let's talk about the first two types.
The arithmetic operation is the addition, subtraction, multiplication, division, and remainder, respectively corresponding to the sign +-*/%. % Is the remainder, not division, /.
It must be noted that the computation of a computer is different from that of a real world. For decimals, that is, floating point float, their arithmetic operations are normal. For an integer, the arithmetic operation is strange. Division of integers is not divisible. Only the integer part of the result is obtained, that is, the quotient. For example, the result of 7/2 is 3. As for the overflow and floating point calculation error, it is somewhat advanced.
In addition to arithmetic operations, there are also logical operations. Is with (&), or (|), not (!).
Basically, it is the operation of true or false values, which will be used in condition judgment.

Judgment and loop

Because computer programs are executed sequentially, the execution proceeds from a certain entrance to a certain end. This entrance is called the main function and ends with the end of the main function.
Can I change the execution sequence of sequential execution? The answer is yes. Statements and loop statements are judged by conditions.
The condition judgment is generally.
If (...)
{...}
Else
{...}
Basically, to judge a condition, if it is true, execute the following statement; otherwise, execute the statement after Else.
If can be nested to form
If (...)
{...}
Else if (...)
{...}
Else if (...)
{...}
...
Else
{...}

Next we will talk about the loop. It can be said that there is no computer program without loops. Its importance is self-evident.
Loop means to execute a program repeatedly until a certain condition is met and jump out of this loop. In C, the for loop and the while loop are mainly used, but the while loop is relatively basic. They can convert each other, but in most cases, for is more convenient.

Array, structure, pointer

An array is a continuous memory variable that has multiple elements of a certain type.
For example,
Int;
It is a variable that only occupies a portion of memory. If an array is declared, multiple int-type variables can be declared. Array declaration
Int A [10]
This syntax declares an integer array with ten elements.
Then there is the structure.

The structure is a complex data type. It is generally composed of many simple data types (that is, integer floating point type or something.

As for pointers, they are a special type of variables. The value stored in it is a memory address, and the memory where the memory address is located may store some other data. Pointers are relatively difficult. Beginners do not need to learn clearly. They can take the exam.

Function

A function is the execution unit of a program, but a layer higher than a statement. The statement is the most basic unit for execution, and the statement forms a function.
Generally, a program is executed from a function. For C-language programs, the starting point of all programs is the so-called main function. Other functions can be called within a function. In this way, functions, as the unit of a function, are combined to complete different functions, and become a relatively large function to complete complex computing.
The function must be defined and called.

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.