C Language (ii): C language Overview

Source: Internet
Author: User

Study notes:

    •  Operator
    • Function
    • A simple C-language program
    • Integer variable
    • Line break
    • Comments
    • Key words

Overview: What does the C language program look like? Browse this blog, meet the C language of many examples, the beginning of the C language program may feel some strange, however, in the course of learning, you will love them, if you are familiar with other than the C language, will have a sense of déjà vu in C.

#include <stdio.h>     /header file function call module

int Main (void)          

{

int num;         /define num variable

num = 1;& nbsp      /assigning variables

 

printf ("I am a Simple");

printf ("Conputer. \ n ");     /Use the printf function

printf (" My favorite number is%d because it is first.\n "; num);

return 0;/return value is 0

 1.1 Example explanation

6 types of statements in the C language:

  • Label statement
  • Compound statement
  • An expression statement
  • SELECT statement
  • Iteration statements
  • Jump statement

This is explained by the previous top code:

  • #include <stdio.h>//include another file
  • int main (void)//function name
  • /* *//Notes
  • {}//function body start
  • int num; Use a variable named num, and the variable is of integer type
  • num = 1; Assigning values to variables
  • printf ("I am a Simple"); Call the printf function
  • printf ("computer.\n"); Call the printf function
  • printf ("My favorite number is%d because it is first.\n"; num ")//Call printf function

 1.2 C language Features explained:

  • #include <stdio.h> #include是一条C预处理器指令 (perprocessor derective), The stdio.h file contains input and output functions (such as printf) that are used by the compiler, and typically the top information for the C language is called the header file
  • Main () function # The C program must be executed from the main () function, and the main () function has to be a starting function.
  • Note # in a C language program, called comments, which are enclosed by/*/Two, write comments that allow others or yourself to clearly understand the code you're writing.
  • curly braces, function bodies, and blocks # first, let's look at the brackets that are commonly used in C programs, {} is curly braces, () is parentheses, [] is square brackets.
  • Declaration of a # declaration (Declaration), which is one of the most important features of C language.
  • Data Type # The C language can handle multiple types of data, such as integers, characters, and floating-point numbers. The computer can store, read, and interpret data correctly by declaring the variable as an integer or a character type.
  • the name of the variable # the statement that named the variable needs to make sense, such as some identifiers and variable names, for example, you want to define a number of sheep, should be defined as: Sheep_count instead of x xx, if the variable name cannot express its own purpose, then you can use comments to enter Line description.
  • Assignment # num = 1 This line of code is an assignment expression statement, and assignment is one of the basic operations of the C language.
  • printf () function # parentheses table name printf is a function name. The contents of the parentheses are the information passed from the main () function to the printf () function, where the void transfer past value is null.
  • Return Statement # has a return value of the C program has to have a return value statement, where the return value is void, that is, no, empty, so we write return 0.

1.3 Good programming code style:

Absrtact: In programming, a good programming habit can let others in front of a bright, big God or small white programming level from the code style can be seen, you can adopt the following suggestions:

    • At the beginning of the program, comment on what your program is for and what it uses.
    • The naming of variables requires caution, and the naming of variables is related to where the meaning of variables is.
    • In the main section notes need to write clearly what their own code is doing
    • Separating conceptually multiple parts of a function with a blank line
    • One row per statement
    • Defining multiple variables in the C language can be separated by commas

How do I find errors in my code?

First, before compiling, you can see whether the source code can find obvious syntax errors, next to see if the compiler found errors, check the syntax of errors is one of the common compiler errors, when compiling the program, the compiler found that errors will report error messages, the nature and location of each error

keywords and reserved identifiers:

Keywords are the words of the C language. They are special for the C language and cannot be used as identifiers (for example, variable names). Many keywords are used to specify different types, such as int.

  

C Language (ii): C language Overview

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.