Clear, practical technology insights BSOD Code Lookup · Windows Error Code Lookup · Wi-Fi Troubleshooting · PC Troubleshooting Checklist

Basic Syntax of C Programming

Explore Basic Syntax of C Programming with clear explanations, practical examples, and useful tips.

Table of Contents

This guide covers basic syntax of c programming with practical context and easy-to-follow details. Use it to understand the subject and apply the information confidently.

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 ky hieu khong the thuc hien goto sizeof volatile default if static khi co so 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

FAQ

What should I check before following these steps?

Confirm device and software compatibility, save important data, and make sure you have the required permissions, files, and account access.

Why might the process not work?

Common causes include outdated software, missing permissions, incompatible hardware, an unstable connection, or completing a step in the wrong order.

Can I undo the changes if necessary?

That depends on the tool or setting. Use built-in restore options when available, keep a backup, and record the original configuration first.

Discussion

Reader Comments 0

Sign in with email or Google to join the discussion.