C Language Study Notes (1) -- C Language

Source: Internet
Author: User

 

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

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.