Does the C language itself have input and output statements?

青灯夜游
Release: 2022-11-24 14:29:05
Original
13275 people have browsed it

No. The C language itself does not provide input and output statements. Input and output operations are implemented by functions. The purpose of not treating input and output as statements provided by the C language is to make the C language compilation system simple, because the instructions for translating statements into binary are completed during the compilation phase. The absence of input and output statements can avoid dealing with hardware-related issues during the compilation phase. , which can simplify the compilation system, has strong versatility and good portability, is applicable to various types of computers, and is easy to implement on various computers.

Does the C language itself have input and output statements?

The operating environment of this tutorial: windows7 system, c99 version, Dell G3 computer.

The c language itself has no input and output statements. The C language itself does not provide input and output statements. Input and output operations are implemented by functions, and reading and writing files are also implemented using library functions.

The standard function library of C language provides some input and output functions, such as: printf function and scanf function. However, the printf and scanf functions are not keywords in the C language, just the names of the functions.

The functions provided by C are stored in the system in the form of libraries. They are not part of the C language text. The purpose of not treating input and output as statements provided by C language is to make the C language compilation system simple, because the instructions for translating statements into binary are completed during the compilation phase. No input and output statements can avoid processing with the hardware during the compilation phase. Related issues can simplify the compilation system, and it is highly versatile and portable. It is applicable to various types of computers and is easy to implement on various computers.

Various versions of C language function libraries are written by various computer manufacturers for a certain type of computer, and have been compiled into object files (.obj files). During the linking phase, they are connected with the object files compiled from the source program to generate an executable object program. If there is a printf function in the source program, it is not translated into a target instruction during compilation, but the printf function in the connected function library is called during the execution phase.

Expand knowledge:

Unlike other computer programming languages, most functions in C language are implemented through function calls , so the number of statements in C language itself is small. The C language adopts a method that makes the expansion of language functions very convenient. If you need to add new functions, you only need to add the corresponding functions in the function library; and if the function of a function needs to be adjusted, you only need to modify the code of the function itself, but you do not need to modify other programs that call the function. .

The functions in the C language are called system functions. Users can directly call these functions to complete the corresponding functions. For example, printf, fabs, etc. are all system functions. System functions are stored in system files called "C function libraries". When a function needs to be used, the system should be notified of the function library where the function is located. This is achieved by including a header file. For example, the basic framework of the C program shown below:

#include "stdio.h"
#include "conio.h"
int main(void)
{
     /* 此处添加你自己的代码 */
     getch();
     return 0;
}
Copy after login

#include "stdio.h"The preprocessing statement is to notify the system to include the stdio.h header file into this program file, so that you can use the system functions that have been defined in it.

The basic input function in C language is realized by using the function scanf, and the basic output function is realized by using the function printf. The header files of these two functions are stdio.h, but since these are two very commonly used functions, the C language stipulates that the corresponding #include# can be omitted when using these two functions. ##Order.

#include is called the file inclusion command, which is used to introduce the corresponding header file (.h file). #include is also a type of C language preprocessing command. The processing process of

#include is very simple, which is to insert the contents of the header file into the location of the command, thereby connecting the header file and the current source file into one source file, which is the same as copying Pasting has the same effect.

#include can be used in two ways, as follows:

#include 
#include "myHeader.h"
Copy after login
Use angle brackets

< > and double quotes " " The difference is that the search paths for header files are different:

  • Use angle brackets

    < >, the compiler will search for header files in the system path;

  • With double quotes

    " ", the compiler first searches for the header file in the current directory. If it is not found, it then searches for it in the system path.

In other words, using double quotes provides one more search path than using angle brackets, and its function is more powerful.

Notes on #include usage:

  • One #include command can only contain one header file, and multiple header files require multiple #include commands.

  • The same header file can be introduced multiple times. The effect of multiple introductions is the same as the effect of one introduction, because the header file has a mechanism to prevent repeated introduction at the code level. We will discuss the specific details. Explore in depth in the article "Preventing C Language Header Files from being Repeatedly Included".

  • File inclusion allows nesting, which means that another file can be included in an included file.

Related recommendations: "C Video Tutorial"

The above is the detailed content of Does the C language itself have input and output statements?. For more information, please follow other related articles on the PHP Chinese website!

Related labels:
source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template
About us Disclaimer Sitemap
php.cn:Public welfare online PHP training,Help PHP learners grow quickly!