Basic Syntax


You have seen the basic structure of a C program, so it will be easy to understand other basic building blocks of the C programming language.

C Tokens

A C program consists of various tokens and a token is either a keyword, an identifier, a constant, a string literal, or a symbol. In C programming program is a collection of tokens that are keyword,a literal,a symbol or constant value.

The following token is given below
  • Keywords
  • Identifiers
  • Constants
  • Strings
  • Special Symbols
  • Operators
Keyword

There are 32 keyword are reserved. The following list shows the reserved words in C:-

Tokens Tokens Tokens Tokens
int struct auto double
break else static while
if do sizeof volatile
default goto signed void
continue for unsigned short
float const union return
char typedef register enum
switch long case extern
Identifiers

An identifier is nothing but a name assigned to an element in a program. For example,the name of a variable, function, etc. Identifiers are the user-defined names consisting of 'C' standard character set. As the name says, identifiers are used to identify a particular element in a program. Each identifier must have a unique name.

The following rules must be followed for identifiers:

  • An Identifier name must start with a letter or the underscore character.
  • An Identifier name cannot start with a number.like 2=5.
  • An Identifier name can only contain alphanumeric characters and underscore as (A-z, 0-9, and _ ).
  • No keyword can be used as an identifier.
Constant

Constants are those values that cannot be changed during program execution.

There are 32 keyword is reserved. The following list shows the reserved words in C.

Syntax
const type constant_name;
Example
#include<stdio.h>
main()
{
  int side = 10;
  int area;
  area = side*side;
  printf("The area of the square:%d",area);
}
Strings

A string in C is merely an array of characters. The length of a string is determined by a terminating null character: '\0'. So, a string with the contents, say, "abc" has four characters: 'a', 'b', 'c', and the terminating null ('\0') character.
The terminating null character has the value zero.

Example
char c[] = "abcd";
Special Symbols

The following special symbols are used in C having some special meaning and thus, cannot be used for some other purpose.

Symbol Meaning
~ Tilde
# Number sign
! Exclamation mark
$ Dollar sign
% Percent sign
^ Caret
& Ampersand
* Asterisk
{} brace
: Colon
; Semi-Colon
Operators

C operators are symbols that trigger an action when applied to C variables and other objects. The data items on which operators act upon are called operands.

The operator can classify into two parts
Unary Operators

Those operators that require only a single operand to act upon are known as unary operators.

Binary Operators

Those operators that require two operands to act upon are called binary operators

Escape sequence:- Meaning
\n New line
\a Alarm
\t Carriage Return
\b backspace
\t Tab(Horizontal)
\v Vertical Tab
\\ Backslash
\0 Null
\? question Marks.
\nnn Octal number
\xhh Hexadecimal number