C fundamentals

Download as docx, pdf, or txt
Download as docx, pdf, or txt
You are on page 1of 3

Token:-

In a passage of text ,indidual words and punctuation marks are called tokens.in a C program the smallest units are known as as C
tokens.C has six types of tokens i.e Keywords constants,strings,operators,identifiers,and special symbols.
When complie scans the text in ur source code and converts them into token during copilation
Example lena hai.
Tokena re useful for compiler to detect errors.when tokens are not arranged in a particular sequence ,the compiler generates an
error msg.
Character Set:-

Keywords and Identifiers

Keywords are also known as the reserve words. Keywords have fixed meanings and these meaning can’t be
changed. There are 32 keywords whose meaning have been explained to the compiler. Keywords serve as
basic building blocks for program statements. All keywords must be written in lowercase.
C Keywords:
auto break double int struct
break else long switch case
enum register typedef char extern
return union const float short
unsigned continue for signed void
default goto size of volatile do
if static while

Identifier refers to the names given to various program element such as variables, functions and arrays.
These are user-defined names and consist of a sequence of letters and digits, with a letter as a first
character. Both uppercase and lowercase letters are permitted. The underscore character is also permitted.
An underscore is used in the middle of an identifier.
EX:-a,area,sum,emp_name,emp_id,first_name

Constants:
ANSI C allows you to declare constants. When you declare a constant it is a bit like a variable declaration
except the value cannot be changed.
The const keyword is to declare a constant, as shown below:
int const a = 1;
const int a =2;
Note:
 You can declare the const before or after the type. Choose one and stick to it.
 It is usual to initialize a const with a value as it cannot get a value any other way.
The preprocessor #define is another more flexible method to define constants in a program.
You frequently see const declaration in function parameters. This says simply that the function is not going to
change the value of the parameter.
Basic types of constants:
Constants

Numeric Constants Character Constants

Integer Real Single char String


Constant Constant Constants Constant
s s s

 Integer Constants:
An integer constant refers to a sequence of digits. These are of three types
a. Decimal
b. Octal
c. Hexadecimal

 Real Constants:
These quantities are represented by numbers containing fractional parts like 17.548. Such
numbers are called real constants.

 Single Char Constants:


These contains a single character enclosed within a pair of single quote marks.
Example: ‘5’ ‘X’

 String Constants:
A string constant is a sequence of characters enclosed in double quotes. The characters may
be letters, numbers, special characters and blank space. Examples:
“Hello!” “1987” “WELL DONE”

 Backslash Character Constants


C supports some special backslash character constants that are used in output functions. For
example, the symbol ‘\n’ stands for new line character. Although they contain two character but
they represent a single character.

Backslash Character Constants

Constants Meaning
‘\a’ Alert
‘\b’ Backspace
‘\f’ Form feed
‘\n’ New line
‘\r’ Carriage return
‘\v’ Vertical tab
‘\’’ Single quote
‘\”’ Double quote
‘\?’ Question mark
‘\\’ Backslash

1 Statements
A program is made of a number of statements. In C, all statements must end with a semicolon ( ;). C ignores
whitespace, meaning you can put spaces, tabs and new lines in statements without altering the meaning. Statements may
be grouped together in blocks by wrapping them in braces: { and }.

You might also like