C language self-use self-study notes (1)

C++ C language

C++ file suffix name xxx.cpp
C language file suffix name xxx.c
C++ is backward compatible with C
, so generally use cpp suffix name

function

//Indicates the comment
main
return
insert image description here
In programming languages, the function can be regarded as a machine, and our content is encapsulated in the function . We only need to input some things, and we can output what we want.
insert image description here

  1. int indicates that the return type of the function is an integer type
  2. The function must first enter some values, which are defined in (), or not.
  3. There are some things that can be handled inside the function, which are defined in { }.
  4. Functions can return some value. return Returns the return value of the function, such as returning 0, 0 is an integer, which corresponds to the previously defined return value type int.
    insert image description here
    The writing method of the function:
    insert image description here
    such as: input two integers, return the addition result.
    insert image description here

calling function (main function)

Where can the function be called? - main function

insert image description here
The compiler will read the code in top-to-bottom order.
insert image description here
insert image description here
If the order is reversed, the compiler will report an error because the compiler does not understand the add function.
insert image description here
The add function is called by the main function main
, so who calls the main function main? Does the return value type have to be an integer int?

insert image description here

variable

We can think of variables as empty boxes
and put any value of the same type in the box.
Note: variables in c language must be declared before use (python can be used directly)
insert image description here
insert image description here
insert image description here

identifier keyword

Identifiers are names we define ourselves to represent variables, functions, other entities, etc.
insert image description here
Identifiers must be declared or defined in order to be run by the compiler.
insert image description here

Identifier Naming Rules

insert image description here

Key words

insert image description here
int is not an identifier - int is not something we named arbitrarily, int is not the name of any entity, int is a keyword in C language.
insert image description here
All keywords in C language:
insert image description here

constant

Constants are invariants
insert image description here
. String constants should not be declared.
insert image description here
Variables can be modified by assignment, while constants cannot be modified, that is, constants cannot be assigned.
insert image description here

printf function

insert image description here
printf is formatted printing
insert image description here
. The first position in the brackets of printf() must be a string
. In addition to directly passing in a string, it can also be printed by means of placeholders.

placeholder printf

printf prints the variable result with placeholders.
insert image description here
Use printf to print out integers:
insert image description here
insert image description here
insert image description here
the output of this operation is: A=123 B=456

include command

#include can copy the code in the header file stdio.h into our code.
insert image description here
To call a function, you must first define the function.
For example, the printf function is a built-in function of the system. When we call the printf function, the content of the printf definition function is written in the header file.
insert image description here
The function definition of the printf function is written in this file, so when we refer to it, we can call it directly. No need to define it again in its own code file.

Guess you like

Origin blog.csdn.net/weixin_45942265/article/details/124447780