02-Basics of Fundamentals of Programming
02-Basics of Fundamentals of Programming
BASICS OF C LANGUAGE
Abdul Wahab
Lecturer in IT
IECS, UST Bannu
awustb@gmail.com
• For example:
const int a=20;
const char ch=‘M’;
2
Variable
• A quantity whose value may change during execution of
the program is called variable
3
Rules for Writing Variable Names
• The first character of the variable name may be an
alphabetic character or an underscore ( _ )
4
Rules for Writing Variable Names contd…
5
Note
• C/C++ is a case sensitive language.
• For example:
6
Examples of Valid and Invalid Variables
Variable Name Valid/ Invalid Remarks
Ahmad Valid
4percent Invalid Start with a digit
double Invalid C reserved word
Double Valid Start with a capital D
Foxpro Valid
_small Valid
x-y Invalid Special characters are not allowed
Father Name Invalid Space is not allowed
Father_Name Valid
$xyz Invalid
for Invalid C reserved word
7
Data Types used in C/C++
• The type of data is called a data type
8
Integer Data Type
• An integer represents a whole number, that may be
positive or negative
10
Char Data Type
• The char data type consists of alphabetic characters,
numeric digits and special characters
11
Boolean Data Type
• Boolean data type is named after a famous mathematician
Jorge Boole who invented boolean algebra
• Its size is only 1 byte and takes either True or False values
12
Declaration of Variables
• Creating variables in a program is called declaration of
variable
13
Declaration of Variables Contd…
data_type name_of_variable(s);
• For example:
int ab;
float sqr, div, fy;
char ch, z;
14
Initialization of Variable
• Assigning value to a variable is known as initialization of
variable. For example:
sum=100;
15
Have a Good Day !