I have been using java for a long time. Now I am very happy to learn the C language and expand my career.
1. The first c program:
# Include "stdio. h"/* this line is the file inclusion command */
Main (){
Printf ("test");/* function call: printf outputs the content to the display */
}
Note: The C language is case sensitive;
The program must contain one primary function with only one name as main;
Each program line must end;
/*... */Is the comment content.
2. Example: calculate the area and perimeter of any radius circle.
# Include "stdio. h"
Main (){
Float r, l, area;/* defines the float Type Variable */
Scanf ("% f", & r);/* call the keyboard input function */
L = 2*3.14 * r;
Area = 3.14 * r;
Printf ("\ n l = % f, area = % f \ n", l, area );
}
Note: r, l, and area are float variables that can be changed during the program running. float is a data type in C.
3. Calculate the sum of two numbers.
# Include "stdio. h"
Main (){
Int I, j, sum;
Int Add (int m, int n);/* declare a function */
Scanf ("% d", & I, & j );
Sum = Add (I, j);/* call the function */
Printf ("\ n sum = % d \ n", sum );
}
Int Add (int m, int n) {/* function */
Return m + n;
}
Note: The & operator in scanf ("% d", & I, & j); is the get address operator.
Summary of the above three examples:
1. a c-language source program can be composed of one or more source files. Each source file can be composed of one or more functions. A source program can contain no matter how many source files or functions, you can only have one and only one mian function.
The Instruction introduced by "#" is a preprocessing instruction.
4. common syntax specifications.
Identifier: variables, function names, and labels in the program are collectively referred to as the identifier. The C language specifies that the identifier can only contain letters, numbers, and underscores (_). The first character must be a letter or underscore.
From letthinking's column