Basic syntax of C programming

You already know about the basic structure of the C program, now you will easily understand the basic blocks in the C language.

The Token in C

In C language, there are many different tokens and a token can be a keyword, an identifier, a constant, a string or a character. For example, the following C command line includes the following 5 tokens:

 printf ( "Hello, World! n" ); 

Separate tokens are as follows:

 printf ( "Hello, World! n" ) ; 

Semi-colon ; in C

Program C, semicolon is part of the command end. In fact, each command in C must end with a semicolon. It informs the end of a logical attribute.

The following example is 2 commands:

 printf ( "Hello, World! n" ); return 0 ; 

Comment in C

The comment is the same as the help in C program and is ignored by the compiler. It starts with / * and ends with * / as below:

 /* Day la chuong trinh C dau tien */ 

You cannot add a comment section inside this comment section.

Identifier in C

An identifier in C is a name used as a user-defined variable, function, and component. An identifier can start with characters A through Z, a to z and underscore (_) and 0 to 9.

C does not allow signs such as @, $, and% in identifiers. C is a language that distinguishes lowercase letters - uppercase letters . Therefore, QTM and qtm are two different identifiers in C. Here are a few valid identifiers:

 nam hoangminh abc ha_noi a_123 sinhvien _hocphi j d23b5 nhanVien 

Keywords in C

Below is a list of keywords that are reserved in the C language. Identifiers or variables, constants cannot name the same as the keywords below, otherwise the program will report an error.

auto else long switch break enum register typedef case extern return union char float short unsigned const cho ký hiệu không thể thực hiện goto sizeof volatile default if static khi có số struct _Packed double

White space in C

A line may contain spaces, possibly comment lines, known as white lines when the same compiler is ignored when compiling.

A space in C can be a blank paragraph, tab, newline (new line) or comment. A space divides a part of a command into parts and helps the compiler distinguish a component in a command, such as int, end the component, and start the next component as follows:

 int diemthi ; 

There must be at least one character space between int and diemthi for the compiler to understand and distinguish them. On the other hand, see the command below:

 luong = luongcoban + phucap ; // tinh tong luong 

There is no need for a space between the space and the = sign, or between = and luongcoban.

According to Tutorialspoint

Previous article: Basic C program structure

Next lesson: Data type in programming C

3.5 ★ | 2 Vote

May be interested

  • Data type in C programmingPhoto of Data type in C programming
    in the c programming language, data types refer to the system extension used for variable declarations of different types. the type of variable determines the amount of memory used to store that variable and how the bits are stored when released
  • Variable in C programmingPhoto of Variable in C programming
    a variable in c is nothing but a name given to storage memory so that the program can be manipulated. each variable in c has a defined type, to determine the size and layout for that variable memory. the range of values ​​that can be stored in memory, setting of expressions can be applied to variables.
  • Constant in programming CPhoto of Constant in programming C
    constant refers to fixed values ​​that the program cannot change during execution. those fixed values ​​are also called literals.
  • Storage class in C programmingPhoto of Storage class in C programming
    a storage class defines the scope (visibility) and the lifetime of a variable or / and functions in the c program. the preceding type specifications can be changed. here are the storage classes that can be used in the c program.
  • Operator in programming CPhoto of Operator in programming C
    operator is a symbol that tells the compiler to perform a certain mathematical operation or logical operation. language c has a lot of operators and provides operator types.
  • Flow control in C programmingPhoto of Flow control in C programming
    flow control structures require the programmer to determine one or more conditions to evaluate and test by the program, along with the commands to be executed if the condition is determined to be correct, or other commands are executed. if the condition is wrong.