One of the TC programming manuals

Source: Internet
Author: User
Tags exit goto range

This article is the first section of TC, mainly introduces some basic TC related knowledge, and focuses on the circulation, variables and other TC basic concepts of the easy to mix the Xiao part of the analysis, that is a beginner's guide to programming, can also be counted as the "C to program" some supplement. Before we get into the programming section, let's take a closer look at the build environment of turbo C so that you can be more handy when programming.

File menu

pick--quickly reads the last 9 files. (It's really a very handy feature, especially in the DOS era ^-^)

Write to--to save the contents of the file and support DOS wildcard characters. (equivalent to the current save as ...)

OS shell--temporarily leaves Turbo C and executes DOS commands from the DOS environment, entering command exit to return to Turbo C. (DOS window for DOS times?) )

Run Menu

Program reset--Clear the debug information in memory and free up memory space. (Breakpoints and variable information will not be cleared.)

Go to cursor--runs the program to the cursor location.

Trace into--executes the current program in a single step, and the current execution line is highlighted. (This operation can enter the called function)

The step over--function is the same as trace into, but does not enter the called function.

Compile Menu

Make EXE file--compile, connect programs, build executable files.

The link EXE file--only connects without compiling the program and generates the executable file. (a target program is required.) obj file)

Build all--recompile all files in the project (see the Project menu section), but does not check for obsolescence. (That is, if the date of the source file is earlier than the target file date, the source file is not compiled)

Project Menu

Project name--Select an item file that contains the source file name to be compiled. (If the reader to this part of the puzzle, you can put the issue to the launch of the Network forum, will be I or other flying network technical staff to give answers)

Auto dependencies--When the switch is turned on, the source file is checked against the corresponding. Obj file date and time, such as different time to compile again.

Options Menu

Please see this site LZC, small strong "Turbo C 2.0 set detailed", here no longer repeat.

Debug menu

evaluate--when the program is running, this command can view and modify variables in memory and other similar items.

The call stack--program is run to check the stack condition.

Find function--is used to display the specified function when the program is run.

Refresh display--If the edit window is accidentally overridden by a user window, you can use this command to recover the contents of the editing window.

Display swapping--is used to control the exchange conditions between the editing window and the user window, with the smart, always, none three modes.

Break/watch Menu

Used to control breakpoints and watch expressions

After reading the above introduction, I believe you have been surprised by the function of TC, think the first more than 10 years ago in the DOS era, can have a function so powerful compiler but many programmers dream of things. So now the students can not abandon the TC interface simple, limited function, anxious to touch what VC, or first calm down, the TC to learn it.

With a further understanding of TC, let's go to the C language itself.

Understanding the execution process, now let's talk about the statement. A statement is the basic unit of a program, it can complete a specific operation, the combination of the statement of the organic sequence can achieve the specified computational processing functions. More difficult to grasp is the process control statements, the following we on the process control statements in the confusing part of the description.

SELECT statements (if and switch)

In general, a simple branch structure program is implemented with an if statement, and a multi branch structure program is implemented with switch and break. Although it is possible to implement multiple branching structures with nested IF statements, a more concise and straightforward procedure with switch and break implementations should be more attentive to beginners. It should also be noted that because the value of the expression is not 0 true and 0 is false, an expression with a value can also be used as a control condition for an if statement.

Loop statements (for, while and Do-while)

First of all, the reader should understand that the general use of some kind of circular statement of the program section, can also be implemented in two other circular statements. Of course, in practical applications, for statements are used for the problem of the number of loops, and the problem of not determining the number of cycles is a while statement or Do-while statement is more natural. Readers should also be aware of the various changes in the three expressions of the for statement, such as omitting some or all of the expressions, and even writing the loop body into the expression, while the loop body itself becomes an empty statement to satisfy the grammatical requirements of the circular statement.

Transfer statements (break, continue, return, Goto)

For break and continue, here's a reminder that breaks, in addition to being used in switch statements, are often used to force end loops in circular statements, while continue is used only to skip a certain time. If a switch statement exists in a loop and the switch contains a continue statement, the continue skips over the entire loop rather than a case in the switch. Return statement please see the function section. Goto statement can be conveniently in the process of execution of the program to jump, but the goto statement will disrupt the process of the program, reduce the readability of the program, in the structured program design, do not advocate the use of goto statements, ANSI C, the author has said; "Formally, the Goto is never necessary, and in practice it are almost always easy to write code without it. " So there is no more introduction to the Goto statement. If you really want to play a game, use it to exit the deep nesting, for example:
For (...)
For (...) {
...
if (disaster)
Goto error;
}
...
Error: ...

Finally, let's discuss variables, which are an abstraction of the memory space occupied by the data in the program. Let's take a look at the type of variable first.

ANSI Standard Rules shaping variable property sheet

Data type

Number of bytes occupied

Bits

Take value range

Int

2

16

-32768--32767

Short[int]

2

16

-32768--32767

Long[int]

4

32

-2147483648--2147483647

Unsigned[int]

2

16

0--65535

unsigned long[int]

4

32

0--4294967295

Real number base Type table

Real type

Number of bytes stored

Minimum range of values

Effective bit

Float

4

10^-38--10^38

6-7

Double

8

10^-308--10^308

15-16

Long double

16

10^-4932--10^4932

18-19

In C, we can also set the storage properties of variables, determine where the variables are stored, and C defines 4 storage properties: Auto register extern and static.

The default in TC is auto type, the scope is the current function, and the storage space is freed at the end of the function.

Register variables are stored directly in the CPU registers, which is characterized by greatly accelerated operation speed, register variable can only be int or char, and there are number limit (TC 2), so register variables are used to act as counter variable use. Because variables are stored in registers, they cannot be addressed, for example, you cannot use the address operator "&" to ask for a register variable. By the way, TC automatically puts the frequently accessed variable into the register (you need to set the relevant option to on).

External variables must be defined outside of all functions to open up storage space for variables. If you want to access this variable in a function, you need to declare it with extern. Of course, extern can be omitted if the external type variable is defined before the function call. Because an extern variable can be easily invoked at any time, it is tempting to define most variables as an extern variable, but an extern variable is always in memory, consuming not only a lot of storage space, but also variable values that are easily inadvertently altered, causing unpredictable errors, and makes the program difficult to modify.

For some beginners, the static variable may be more difficult to understand, here is an example to illustrate the difference between static and auto. For example, define variable A as static and auto, and set its value to 1. "Int x=1;" The meaning is to assign an initial value to a variable, equivalent to the following two statements "int x;" X=1; ", while the" static int x=1; " The meaning is to describe a static variable and initialize it, the initialization is before the program executes, the compiler one-time to assign the value of the initial "X=1", and in the actual run of the variable is no longer assignment operations.

For ease of understanding, the four storage variables are summarized as follows:

Characteristics of four storage variables

Performance

Auto

extern

Static

Register

External

Internal

Memory ability

No

Yes

Yes

Yes

No

Multiple function shares

No

Yes

Yes

No

No

Different file shares

No

Yes

No

No

No

Initialize Assignment

Random

0

0

0

Random

Scope

Current function

The entire program

Current file

Current function

Current function

After figuring out the variables, the basic introduction to TC is also a close, if you feel that this article does provide you with some help to learn TC, then please pay attention to the TC Programming Manual of the two---functions and arrays.

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.