Download as pdf or txt
Download as pdf or txt
You are on page 1of 8

Prepared By: ER.

Kamal Gyawali

Keywords:
 Keywords are predefined words for a c programming language.
 All keywords have fixed meaning and these meaning cannot be changed.
 C keywords are listed below.
int if break
float else case
char switch continue
double do goto
void case while

Identifers:
 Every word used in c program to identify the name of variables,
functions, arrays, pointers and symbolic constants are known as
identifiers.
 The rule for naming identifiers are:
i) It must be a combination of latters and digits and must begin
with latter.
ii) Underscore is permitted between two words, but white space
is not allowed.
iii) Keywords cannot be used.
iv) It is case sensitive, i.e. uppercase and lowercase letters are not
interchangeable.

Variables:
 A variable is symbolic name which is used to store data item.
 Rule for naming variable are same as rule for naming identifier.
 Some examples of valid variable names are:
nepal first_name
num1 sum

 Some examples of invalid variable names are:


1nepal (total)
Prepared By: ER. Kamal Gyawali

%male first name

Variable declaration:

Syntax:

Data_type variable_name;

For example:

int n;

float radius;

char gender;

Tokens:
The basic elements recognized by c compiler are called tokens. A token is
source program text that the compiler does not break down into component
elements. The keywords, identifiers, constants, operator are example of
tokens.

Token

Keywords identifiers constants Operators Special symbols


Prepared By: ER. Kamal Gyawali

Data types:[2018 fall, 2014 spring, 2017 spring, 2018 spring]


Data type is a keyword which is used for naming variables and allocating memory.

Basically there are three types of data types.

i. Fundamental (primary) data types.


ii. Derived data types.
iii. User defined data types.

1) Fundamental data types:


Primary data types are categorized into five types.
i. Integer type (int)
ii. Floating point type (float)
iii. Double-precision floating point type (double)
iv. Character type (char)
v. Void type (void)

a) Integer type:
 Integers are whole numbers, i.e. non fractional numbers.
 For example: 11, 55,-7,-123 etc.
 The data type qualifier is int.
 Variable are defined as:
int a;
 It reserves 2 bytes in memory.
 Its conversion character is d.

b) Floating point type:


 Floating point types are fractional numbers (i.e. real numbers).
 For example: 10.458, -8.9785 etc.
Prepared By: ER. Kamal Gyawali

 The data type qualifier is float.


 Variable are defined as:
float radius;
 It reserves 4 bytes in memory.
 Its conversion character is f.

c) Double precision floating point type:


 When the accuracy provided by a float number is not sufficient, the type
double can be used to define the number.
 The data type qualifier is double.
 Variable are defined as:
double a;
 It reserves 8 bytes in memory.
 Its conversion character is lf.

d) character data type:


 A single character can be defined as a character data type.
 The data type qualifier is char.
 Variable are defined as:
char a;
 It reserves 1 byte in memory.
 Its conversion character is c.

e) Void type:
 The void type has no values. This is usually used to specify a type
of function when it does not return any value to calling function.

2) Derived data type:

a) Array:
An array is collection of similar data type.
For example:
Prepared By: ER. Kamal Gyawali

int a[10];
float marks[20];

b) String:
String is the collection of character.
For example:
char name[20];

c) Pointer:
Pointer is a variable which holds address of another variable.
For example:
int a;
int *p;
p=&a;

3) User defined data type:

a) Structure:
Structure is collection of different data type.
For example:
Struct student
{
char name[20];
int roll;
float marks;
};

b) Union:
Union contains members whose individual data types may differ from
one another.
Union
Prepared By: ER. Kamal Gyawali

{
int roll;
float marks;
char name[20];
};

c) Function:
A function is defined as a self-contained block of statements that
performs a particular task or job.
For example:
void main()
void add()
int factorial(int n)

ASCII Values:
1) Conversion of ASCII code to char

Output:

2) Conversion of Char to ASCII value


Prepared By: ER. Kamal Gyawali

Output:

Preprocessor directives:
Preprocessor directive is a collection of special statements that
are executed at the beginning of a compilation process.
Preprocessor directive begins with the symbol # (hash) and do
not require semicolon at the end.
Some examples of preprocessor directives are:
#include<stdio.h>
#include<conio.h>
#include<math.h>
#include<string.h>
#define pi 3.147
Prepared By: ER. Kamal Gyawali

You might also like