C Programming Syntax

In this article of C Programming Syntax, you will know basic C Programming Syntax followed in every c programs.

C Programming Syntax specifies rules for the sequence of characters to be written in C language. In simple language, it states how to form statements in a C language program – How should the line of code start, how it should end, where to use double quotes, where to use curly brackets etc.

The rule specifies how the character sequence will be grouped together, to form tokens. The smallest individual unit in C program is known as C Token. Tokens are either keywords, identifiers, constants, variables or any symbol which has some meaning in C language. A C program can also be called as a collection of various tokens.

 Understand C Programming Syntax by example

#include <stdio.h>
int main()
{
 printf("Hello,World");
 return 0;
}

if I take anyone statement:

printf("Hello,World");

Then the tokens in this statement are→ printf, (, “Hello,World”, ) and ; .

So, C tokens are basically the building blocks of a C program.

Have You enjoyed the article on C Programming Syntax!

Semicolon(;)

Semicolon (;) is used to mark the end of a statement and beginning of another statement.

The absence of semicolon at the end of any statement will mislead the compiler to think that this statement is not yet finished. And it will add the next consecutive statement after it, which may lead to compilation(syntax) error.

#include <stdio.h>
int main()
{
 printf("Hello,World");
 return 0;
}

In the above program, I have omitted the semicolon from the printf(“…”)  statement, hence the compiler will think that starting from printf until the semicolon after return 0; statement, is a single statement and this will lead to compilation error.

Comments

Comments are plain simple text in a C program that is not compiled by the compiler. Programmers write comments for the better understanding of the program.

Though writing comments is not compulsory, but it is recommended to make your program more descriptive. It make the code more readable.

There are two ways in which we can write comments.

  • Using // This is used to write a single line comment.
  • Using /* */: The statements enclosed within /* and */ , are used to write multi-line comments.

Example of comments :

// This is a single line comment

/* This is a multi-line comment */

/* This is a multi-line
valid comment */

// this is not
a valid comment because it's written in multiple lines.

Have You enjoyed the article on C Programming Syntax!

Basic C Programming Syntax

  • C is a case-sensitive language. So, all C instructions must be written in lower case letter.
  • All C statement must end with a semicolon.
  • Whitespace is used in C to describe blanks and tabs.
  • Whitespace is required between keywords and identifiers. You will learn about keywords and identifiers in the next tutorial.

<< Prev                                                                                                              Next >>


Your friends are waiting for this content. Please Share To Aware Them!