[C Language] Learning


foreword

`I will learn operating system + deep learning in the future, so C language is indispensable.


1. warm up

1.1 output helloworld

#include<stdio.h>
void main() {
	printf("Hello World!!");
}

std = standard
io=input and output.h
= help . is a style
include <stdio.h>: The compilation system searches for the header file stdio.h in the directory where the system header files are located.
include “stdio.h”: The compilation system first compiles in the source Search for stdio.h in the file directory, but cannot find the directory where the transfer system file is located Search

"stdio.h" indicates that the priority is the user's level, and if you can't find it, you can find it in the system.

1.2 Examples

Input an integer from the keyboard, if its value is less than 0, output -1, equal to 0, output 0, greater than 0, output 1

#include<stdio.h>
void main(){
	int x; //定义整数变量
	scanf("%d", &x);
	if (x < 0)
		printf("\n -1 \n");
	else if(x == 0)
		printf("\n 0 \n");
	else (x > 0)
		printf("\n 1 \n");
}

Find the sum from 1 to 100

#include<stdio.h>
void main() {
  int i = 1, s = 0;
  while(i<=100) {
  	 s = s + 1;
  	 i = i + 1;
  }
  printf("sum=%d\n",s);
}

printf(s) is wrong, pseudocode, often encountered, but the simplest runnable code also needs printf("%d", s);

1.3 C language program structure

Preprocessing: Processing performed at compile time, such as inclusion, macro #include, #define
function
variable definition format, type sizeof(int) can know the number of bytes occupied and affect the range of values.
Statement group
Notes
insert image description here

Guess you like

Origin blog.csdn.net/weixin_40293999/article/details/130475631