Professional Documents
Culture Documents
Datatype
Datatype
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
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
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.
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.
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;
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:
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