C Language Learning (1)---IDE and BASIC program structure

Source: Internet
Author: User

Any language learning, the first to have an editor or integrated development tools IDE, otherwise the code does not know where to write. For my small white, install an IDE is the best, because C language is also compiled language, after writing code, to compile to run, and the IDE to compile, run all their own, we just click the button, we can run the code. For beginners, can see the code to run successfully is the most happy thing, this also can improve the enthusiasm of writing code, otherwise, come up is a bunch of configuration, some still do not understand, configuration has problems, code can not run, very depressed, still can have the mood to write code? The IDE chosen here is Code::block

Before installing the IDE, download it first, Code::block's official website is http://www.codeblocks.org/. You can also Baidu Codeblock, generally the first one is its official website, the following is the lawsuit:

There is a download in the navigation bar, which is the Blue Bottom tab, click, go to its download page,

Here are three ways to download, with a list of three Li, you can see that each download method is preceded by a black dot tag. We choose the first Download the binary release (underlined), go to its true download page, you can see that it has various versions of the download method, because I am WINDOWS10 system, directly to find win10 on it.

Here to download Codeblocks-16.01mingw-setup.exe, with MinGW, because it has a compiler and debugger, language can be compiled debugging. Install it when the download is complete.

Installation is very simple, in order to avoid configuration errors, I am all the way next, all using the default installation, until the installation is complete, the desktop will have a similar to the Window icon class icon, it is Cold::block shortcut, double-click, you can open it, the interface is as follows:

If the IDE is installed successfully, write the code and see how the IDE develops the program. The simplest is the Hello World program.

In C, we have to build a project before we start writing code. Project, File-New

Click Done, you can see a popup window, it is catagory, is what we want to build what kind of project. Select Console application here, which is the console item (the last icon on the first line), because our program results are displayed in the console.

Click the last icon will pop the window, click Next directly, if you do not want to see this pop-up window, you can tick, skip this page next time check box, and then click Next, this pop-up window does not have a real effect, just hint, we can completely ignore, click Next, A language selection box will appear, C or C + +, we can choose c.

Click Next again to add information about the specific item, such as. Project title is the name of the item, and you can add one, such as Hello. Foler to create project in: Where do you put the project where you can find a place? After the completion of the Add, click Next, there is a complier compiler pop-up window, we do not have to change any place, directly point to finish on it.

At this time back to the editor interface, left workspace below, more than a Hello project, it has a source directory below, is the source of the storage. It has a mian.c, and the program we write is also this style, which provides a template that can be used to get started quickly, and it's written in the Hello World program. All C language programs use. c as the suffix.

When the program is finished, how to run it? In the toolbar there are four small buttons, such as the first jagged small Wheel, is the compilation command, the second Green Start button is executed, the third is the first and the second person's fit, look at the icon can also be seen, it is compiled and executed.

We first click the first button, then click the Second button, or directly click the third button, you can run the program, pop-up console, display Hello World, press the ECS key to exit the console. Later, after writing the code, you can run it directly to see the results.

Now look at the C program code is how to write, is the source of MAIN.C.

First sentence and second sentence: #include <stdio.h>

#: The command starting with the # is a preprocessing instruction, which is to process the code before it runs, and here is the Include<stdio.h>, which introduces the Stdio library.

#预处理指令有时候可以不写, but if you write it, be sure to place it at the beginning of the file.

Stdio, which is a shorthand for standard input and out, is used to define input and output streams. Because printf is an input statement in our file, we want to bring it in.

The. H:h is the header meaning, here refers to the head file.

In the second sentence, int main (), main is a function that is the starting point for the C language program to run. Any C language program must have a main function, and there is only one. Without the main function, the program does not know where to run, and if there are multiple, it will conflict and do not know where to start running. The preceding int, which represents the return value of the program run, returns 0, so it is of type int.

The third line is {}, the body of the main function, which represents what the function is going to do. Here is printf, output content.

Statement to end with a semicolon.

Finally, how to add comments to the program, which is consistent with the syntax for adding annotations to JS.  Single-line comment. /* * * Multiple lines of comments.

Now we can write the code happily.

C Language Learning (1)---IDE and BASIC program structure

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.