C language – Basic Syntax in C Programming Language

basic syntax in c programming language

C language basic syntax

You have seen the basic structure of the C program in the previous lesson, so it’ll be easy to understand other basic building blocks of the C language.

Tokens in c language

A C program consists of varied tokens and a token is either a keyword, an identifier, a constant, a string literal, or a symbol. as an example, the following C statement consists of 5 tokens:

printf("Hello world"\n);

the individual Tokens are:

1.printf
2. (
3. Hello World\n
4. )
5. ;

Semicolon(;)

In the C programming language, the semicolon is a statement terminator. That is, every individual statement must be ended with a semicolon. It indicates the end of one logical entity.

For example, the following are two different statements:

printf("Hello world\n); ----statement1 ended with ;
return 0; -------------------staement2 ended with ;

Comments

Comments are like helping text in your c program and they are unnoticed by the compiler. They begin with/ * and terminate with the characters */ as shown below.

/* my first program in C */

Identifiers in C programming language

A C identifier is a name used to identify a variable, function, or any other user-defined item. An identifier starts with a letter A to Z or a to z or an underscore, followed by zero or further letters, _underscores, and numerals (0 to 9). C doesn’t allow punctuation characters similar to @, $, &, # and within identifiers.

C language is a case-sensitive programming language. Therefore, Hour and hour are two different identifiers in C. Here are some examples of acceptable identifiers

Valid Identifiers :

|smooth | danny | abd | good_language | m_890 | your_name | _temp | s | hj7678 | getVar|

Keywords

Keywords are pre-defined words in the C language. Each keyword is meant to perform a specific function in a C program. Since keywords are referred names for compilers, they can’t be used as a variable name.

For example: int school;

Here, int is a keyword that indicates a school is a variable of type int (integers).

C is a case-sensitive language, all keywords must be written in lowercase, C language has 32 keywords. here is a list of all keywords in ANSI C.

Keywords in c language

White Space in C language

A line containing only whitespace, maybe with a comment, is recognized as a blank line, and a C compiler definitely ignores it. Whitespace is the term used in C to describe blanks, tabs, newline characters, and comments.

Whitespace separates one section of a statement from every other and enables the compiler to pick out where one element in a statement, such as an int ends and the next element begins. Therefore, in the following statement:

int age;

There should be at least one whitespace character (usually a space) between int and age for the compiler to be capable to distinguish them. On the different hand, in the following statement

cars = Lamborghini + Ferrari; //get the total cars

No whitespace characters are necessary between cars and = or between = and Lamborghini, although you are free to include some if you wish for readability purposes.

FAQ's