laitimes

Xiaobai challenged to learn C language the next day ---- basic grammar

author:Interest programming network

I. Introduction

Last time we simply printed out the C language, the entire C program execution is very fast, the compilation runs in one go, but in order to package the program into an executable EXE, we need to use the linker to package it into EXE, as shown in the figure:

Xiaobai challenged to learn C language the next day ---- basic grammar

Because we are using the GCC compiler, the suffix is mainly .o, and if it is vc++, the suffix is .obj. And the above Makefile.win, he refers to the Makefile on Windows, we all know that there is a Makefile on the Linux system, and the meaning of the existence of this file is to provide Windows with automatic compilation, so the configuration inside is generally closely related to the current project's compilation environment, as shown in the figure:

Xiaobai challenged to learn C language the next day ---- basic grammar

But these are all dev C++ doing for us, we don't have to configure it ourselves at all; well, back to the point, let's talk about the basic syntax of C.

2. Notes

Many times we need to add some comments to the program so that we can quickly read the code, let's see how to add comments, as shown in the figure:

Xiaobai challenged to learn C language the next day ---- basic grammar

3. Data types

The data types in the c language are roughly divided into basic types (short integer, integer, long integer, character type, single-precision floating-point, double-precision floating-point, enumeration type), void type, and construction type (array, struct, common body, ). Each type of the primitive type can be preceded by signed and unsigned, that is, signed and unsigned, which is all the basic types, as shown in the figure:

data type Occupied space The range of values
char 1 -128~127 or 0~255
short 2 -32,768~32,767
long 4 -2,147,483,648~2,147,483,647
int -32,768 to 32,767 or -2,147,483,648 to 2,147,483,647
float 1.2E-38 ~3.4E+38
double 8 2.3E-308~1.7E+308

Note: Here we do not list any unsigned and signed types, this is very simple, you only need to add unsigned or signed before the corresponding data type.

4. Rename the data type

If we want to change the names of primitive data types in C, you can do so using typedef, as follows:

Xiaobai challenged to learn C language the next day ---- basic grammar

5. Data type conversion

The data type conversion in the C language can be automatic type conversion or cast, so let's take a look at them one by one.

1. Automatic type conversion

Xiaobai challenged to learn C language the next day ---- basic grammar

Here we can easily get the hexadecimal of the double floating-point type by formatting the output.

2. Cast

Xiaobai challenged to learn C language the next day ---- basic grammar

6. Summary

The knowledge points discussed in this article are mainly for some basic data types of the C language. Although the content is not much, but also need energy to master, sort out these content Xiaobian is also really spent some effort, mainly the online articles on the C language are not comprehensive enough, so I personally sorted it out, dedicated to you who love to learn. Pay attention to the public number simple programming network to see more exquisite cool articles.