The first lesson of C language --------- it is coming, it is coming, and it is coming with salary

Author's Foreword:

This is my gitee repository: https://gitee.com/qin-laoda/python-exercises

Interested little cuties can click in and have a look, there are codes I wrote in it, let's learn from them together

Since my self-introduction has already been introduced, in my first blog, if you are interested, you can check it out,

author's suggestion

Let's briefly introduce the steps to learn C language well:

=> 1. Learn to code, because all programmers start from coding, no one will become good without coding, unless you are writing a novel, or you are daydreaming

=> 2. It’s not enough when we learn to type code, because we are human, we will forget if we are human, no one will remember everything, unless you are a robot, in order for us to consolidate our knowledge, we must learn to do Notes, but also to summarize, I recommend:

Evernote (Youdao Cloud Notes) - notes can be retrieved, notes can not be lost, easy to review anytime, anywhere.

xmind- mind map, sorting out the framework of a course after learning
=>3 . Learn to squeeze time to study, when we want to be better than others, we must work harder than others,
=> 4. When encountering problems, I learn to solve them by myself first, and I can go to Baidu or station b to find answers, because we are in the Internet age
=>5. Develop a good habit of blogging and uploading code to gitee, these two will make you very popular when looking for a job
The above is my suggestion. If the cuties have their own rhythm, they can follow their own pace. It is not necessarily good to use, and the best is to be suitable.

What is C language

C language is a general-purpose computer programming language , which is widely used in low-level development. The design goal of the C language is to provide a language that can be easily
A programming language that compiles in the same way , handles low-level memory , generates a small amount of machine code , and can run without any runtime environment support.
Word.
Although the C language provides many low-level processing functions, it still maintains a good cross-platform feature, written in a standard specification
C language programs can be compiled on many computer platforms, even including some embedded processors (single-chip microcomputer or MCU ) and supercomputers.
computer and other operating platforms.
In the 1980s, in order to avoid differences in the syntax of the C language used by various developers, the National Bureau of Standards established a standard for the C language.
A complete set of American National Standard syntax, called ANSI C , was established as the original standard for the C language. [1 ] Current December 8 , 2011
The C11 standard issued by the International Organization for Standardization ( ISO ) and the International Electrotechnical Commission ( IEC ) is the third official standard of the C language.
It is also the latest standard of C language. This standard better supports Chinese character function names and Chinese character identifiers, and realizes Chinese characters to a certain extent.
word programming.
C language is a process-oriented computer programming language, which is different from object-oriented programming languages ​​such as C++ and Java .
Its compilers mainly include Clang , GCC , WIN-TC , SUBLIME , MSVC , Turbo C , etc.
My understanding of the C language: C language is what we talk to the computer, because the computer stores binary (the computer only knows 0 and 1), we tell the computer how to do it by using the C language,
The following figure can give us a better understanding of the domains where the language is applicable

 How does the C language code we write run:

A simple C language code

code:

#include<stdio.h>
int main()
{
	printf("我的C语言之旅开始了");
	return 0;
}

 result:

Let me explain:

#include<stdio.h> import header file stdio.h

int : shaping

int main() main function, there must be, and there is only one, as the entry point for the program to run

In fact, the way of writing main() is more, if you want to know, you can go to my gitee to get it

printf() function in stdio.h, library function for printing output

return returns; the returned type corresponds to the int of int main()

Other data types:

 Note: C language does not have a string keyword

Floating point means decimal

float has fewer decimal places than double

2: integer

'2': character 2

Let's try the space size of these data types:

code show as below:

#include<stdio.h>
int main()
{
	//单位是字节
	printf("%d\n", sizeof(char));
	printf("%d\n", sizeof(short));
	printf("%d\n", sizeof(int));
	printf("%d\n", sizeof(long));
	printf("%d\n", sizeof(long long));
	printf("%d\n", sizeof(float));
	printf("%d\n", sizeof(double));
	return 0;
}

The result is as follows:

 Here some cuties will have doubts, why are the bytes of long the same as int?

because:

sizeof(char)<sizeof(short)<sizeof(int)<=sizeof(long)<=sizeof(long long)

variables and constants

The above data types are prepared for creating variables and constants

Below I write some variables:

#include<stdio.h>
int main()
{
	int age = 10;
	char name = 'w';
	float weight = 45.5f;//加个f变成float类型
	float height = 45.5;//会默认为double类型的变量
	printf("%f\n", weight);
	printf("%f\n", height);



	return 0;
}

45.5; The default is double type

45.5f; the default is float type

Double type data has more decimal places than float

Global and local variables

code show as below:

#include<stdio.h>
//全局变量
//当局部和全局变量同名时,本质上他们互不干扰,局部变量会优先
//当一个变量定义在一个函数外,这个变量对这个函数来说就是全局变量
int a = 0;

int main()
{
	//局部变量
	int a = 10;	
	printf("%d", a);
	return 0;
}

In my opinion, global variables are for functions. When a variable is defined outside a function, the variable is a global variable for the function, and the variable defined inside the function is called a local variable.

So let's do an exercise:

Enter two integers and print the sum of the two numbers:

code:

#include<stdio.h>
int main()
{
	int a = 0;
	int b = 0;
	int sum = 0;
	//&取地址操作符
	//scanf()库函数--输入函数
	scanf("%d %d", &a, &b);
	sum = a + b;
	printf("%d", sum);
	return 0;
}

The result is as follows:

 scanf() library function --------- input function

&a: Take the address of a

&b: take the address of b

Summarize:

This time, we will briefly introduce the variables and commonly used data types of C language, and we will continue to introduce other variables of C language in the future.

Guess you like

Origin blog.csdn.net/m0_69984273/article/details/131145725