C Syntax Rules | C Programming Basic Syntax

C is high-level programming that can use for writing system software and application software. We will discuss the C syntax rules in the article to explain every line of the programs written in C.

What is Syntax in Programming?

The syntax is some rules that control the structure of the programming language. 

It refers to laws that define the structure of programming language. Without following the programming language syntax, the compiler will be unable to understand the code. Compiler converts programming languages into binary code that makes it easy to understand for computers. But if the syntax is not correct, the code will not compile. Interpreters will also not be able to execute the runtime of programming languages. 

C Syntax Guide

The syntax of the C language fixed the sequence of characters.  

So the syntax explains the way to from statements for C language. Moreover, it states:

  •  How should the line of code start
  •  How it should end
  •  Where to use double quotes.
  •  Where to use curly brackets, etc.

C Language Basic Syntax Rules

Typically, a simple C program consists of header files, a main() function, and the actual program code. The following is the basic syntax of a simple and most minor C program:

Because every C program begins with a main() function, every program must contain a main() function. In this case, print “Hello Compiler” on the output screen using the smallest and simplest C program:

Here is the sample output of the above C program:

From the above program, you can filter out like this:

denotes to

And

denotes to

and then

Denotes to

 

Tokens

The programming language of C is the collection of various tokens. The rule specifies how the sequence of characters will be grouped. C Tokens are the smallest individual units in a C program. C language tokens can be keywords, identifiers, constants, variables, or any other symbol that has some meaning. 

Take a look at the program, 

Tokens in the statement → printf, (“Hello, World,”) and.

C tokens are considered as the building blocks of a C program. 

Semicolon

The semicolon; used at the end of a statement to begin a new one. When a semicolon is missing at the end of any statement, it misleads the compiler. In this case, it will think that this statement hasn’t been completed and continue adding consecutive statements. That occurs compilation (c syntax) error in the program. 

In the above program, the semicolon is omitted from the printf(“…”) statement. Hence the compiler calculates from printf up to the semicolon after return 0 statement, which will lead to compilation error.

Comments in C

In C Programming, comments are like help text in your program. The compiler ignores them. Comments can significantly aid code reviews. A programmer can benefit considerably from given comments during the reviewing process. Programmers can comment on lines of code to provide helpful information or remind them of something related to the code.

Comment types in C include:

  • Single-line comments – start from // to the end of line
  • Multi-line comments – starts from /* and ends with */

Here is an example program that shows both single-line comments and multi-line comments:

Here is a sample output from this C program. On the output screen, you will only see “Welcome to higheredu.com.” And as already told, all the comments are ignored by the compiler because the programmer can only read comments.

Identifiers in C

In C programming, the identifier is used to identify functions or any other user-defined terms. The identifier can be started with letters (A to Z) or (a to z) or through an underscore ( _ ) followed by zero or more letters, underscores, and digits (0 to 9)

C does not allow punctuation characters (special characters) like @, $, and % within identifiers. Since C programming is a case-sensitive programming language. Thus, Total and total are the two different identifiers in C. The identifiers rules should be followed to avoid c programming syntax errors. 

A sample program is shown here. Don’t let anything distract you. In addition, the program indicates that numeric data are different from numeric data or name from the name:

 

Whitespaces in C

Blank lines in C code are known as blank lines and are completely ignored by the C compiler. C programs use the term whitespace to describe blanks, tabs, newlines, and comments. Using whitespace enables a compiler to distinguish between different parts of a statement. Where one element in a statement, like int, ends and the next element begins. Here is this statement:

For a compiler to distinguish int (data type) from sum (variable), there must be one whitespace character (usually a space). Whitespace will be inserted between them; otherwise, it will become int sum and be treated as an identifier.

C Keywords

These are words that are reserved for a specific purpose. These are the C keywords listed in the following table:

 

Share and Enjoy !

Shares

Leave a Reply

Your email address will not be published. Required fields are marked *