Aaronyang C language [1] [Basic Introduction]

Source: Internet
Author: User

I have never been to college, so I don't know C. I have mastered C # And decided to read it.AlgorithmIntroduction, so I want to learn C

I learned C #, so when I learned it, I would think of C #. Then I made a comparison and I learned Java, so I would also think of Java for a comparison.

Basic Concepts

1.Program: Describes how to solve a problem in a computer language that can be understood and executed by a computer

2. Programming: the process of analyzing and recording the solution steps

3. Binary language → assembly language (symbols replace binaryCode, So it is called the symbolic language and machine-oriented language)

4. Advanced Language: C (process-oriented language). Binary and assembly languages are collectively referred to as "low-level languages"

5. a program written in advanced languages is called a "source program". The source program cannot run directly on a computer. It is first translated into a binary language and then executed. Method: ① execute an explanation sentence. The program that completes the translation is called an interpreter ". ② After one-time translation, the program that completes the translation is called the "Compilation Program", and the compiled binary program is called the "Target Program".

6. C language predecessor-ALGOL language (the world's first high-level language, the second is the Fortran language), followed by basic, COBOL, Pascal, etc.

7. Compared with C # features: closer to hardware, easier to describe algorithms than low-level languages, and better performance

Basic knowledge

1. the character set is the same as that of C #. Escape \

2. Reserved Words (keywords), such as if, Int, float, typedef, and C #, which are easy to grasp

3. identifier: the naming convention is the same as that of C #, method name, function name, etc.

4. Vocabulary classification: constant, variable, operator, function call, expression, reserved word, same as C #

5. Statement classification: Data Definition statements, value assignment statements, function call months, expression statements, flow control Statements, Statement compliance, empty statements, and other statements. Similar to C #

6. C program is a sequence of statements composed of C statements. Generally, a C program contains one or more functions, and only one of them is the primary function. The function name is specified as main.

7. Note :/**/

8. C Programs always start with the main function and end with the main function. Basically the same as the console program in C #

C Program Development Environment
(A) WIN-TC (the use of Turbo C in the book, my computer win7 64-bit, can not run, understand it)

1. Download:Download

2. Installation: continue to the next step, which is simple.

3. Interface

4. The main steps for debugging C Programs in Turbo C are as follows:

  • Enter a new program or call an existing Program
  • Edit and modify source program
  • Source program inventory
  • Compile the connection to generate the Target Program
  • Execute the Target Program
  • Display running results

 

But in win7 64-Bit mode, it won't work when running the program. If you are an XP user, you may be able to use

So I decided to use the C-free tool to learn.

 

 

(2) c-free 5.0 (download: Volume 1 Volume 2 )

The next step of installation is also relatively simple.

Interface

Then click Help-register

Username: tianfang
Email: quart@163.com
Registration Code: 2nnuqd3sho2agta0xnjcusfk1lxo

Restart C-free

Hello world, the first C Project

Create a project

We do not select the third one.

Because my computer has vs2010, select the first one and then complete

Double-click the main. c file.

Enter the following code. printf is equivalent to console. Write in C #.

Like vs2010, press F5 to compile and run the program ,:

However, the generated exe program will be set after it is displayed, and the effect will be displayed.

However, if you run it separately, we used to use console. Readline () in C # To wait for user input, and then we can see that all the effects of the previous input

Let's add a line of scanf code.

Java also uses a word similar to scan, waiting for the user to enter, as if scanner S = new partition (system. In );

Then use

String STR = S. Next ();
Integer I = S. nextint ();

Waiting for user input

We will continue to add a line of code

Press F5 to compile the program.

Next, you can directly

Click it to run the project as in the C # console. the startup speed of the program is very fast. This is incomparable to C #. The WPF project generates the EXE, and I found the slowest startup.

 

 

Other small examples

As a beginner, you still want to try and find that it is really similar to C #.

Calculate the average of the three numbers entered. This is also a small example in the book.

Preparations:

Create an empty shell as above and prepare to write code

Knowledge: Remember % F. We have learned C #. If we know float, F is short for float, which indicates that a float or double type value is input here. After the input, the correct data type is saved directly. For the "%" number, there are other formats.

 

% D integer output, % LD long integer output,

% O outputs integers in octal format,

% X outputs integers in hexadecimal notation,

% U outputs unsigned data in decimal number (unsigned number ).

% C is used to output a character,

% S is used to output a string,

% F is used to output real numbers in decimal form,

% E outputs real numbers in exponential form,

% G automatically selects the F format or eformat based on the size, and does not output meaningless zero.

 

Then prepare the empty shell

Let's write an AVE method. The returned method is a little different from that of C #. the variables are enclosed in brackets, and the others are the same.

Return to the main function and continue coding.

 
# Include <stdio. h>
 
 
FloatAve (FloatF1,FloatF2,FloatF3 ){
 
FloatA1;
 
A1 = (F1 + F2 + F3)/3;
 
Return(A1 );
 
}
 
 
 
IntMain (IntArgc,Char* Argv [])
 
{
 
FloatX1, x2, X3, X4;
 
Scanf ("% F, % F, % F", & X1, & X2, & X3 );
 
X4 = ave (x1, x2, X3 );
 
Printf ("% F \ n", X4 );
 
Scanf ("% F");
Return0;
 
}

Enter 5, 6, 7, and press Enter.

Effect:

This pointAveThe function must be in the main method. Otherwise, the AVE does not exist when the main method is run first, so the compilation will fail.

This is different from C #.

If you want to put the AVE method elsewhere, you need to declare this Ave function before calling the AVE method in the main method.

The Code is as follows:

Then you can.

The % F comma after scanf serves as a link character, for example, I changed it to this

:

Learning Summary
    1. Have a basic understanding of C
    2. There is a basic comparison between C and C #.
    3. It is not difficult to learn C
    4. Use C-free for development
    5. It is easy to write a small program with better performance than C #.
    6. Next, it will be easy to learn C slowly.

 

 

 

 

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.