You are on page 1of 12

Lecture No 1

Variables and Data types

Variables
Variables are analogous to Buckets or

Envelopes where information can be stored.
We call buckets by names so Variables must
have names for calling.
Information stored in Variables can also be
changed.
Name of the variable is anything your name
also.

Data Types
Data types tell about what type of value our

variable want to store
It may be INT FLOAT DOUBLE CHAR STRING
Int:-It will take only integer value no value
after decimal point
Float:-It will take values after decimal point
but has less precison also known as floating
point.
Double:-Also called floating point because
decimal points flaot more precise than float

Data Types Continued
Char:-It only takes a character it is one byte

only takes only character
For examples
Int =10
Float=10.232
Double=10.32322
Char =‘d’
Char =‘+’

Assignment Operator
Assignment operator “=“ is used to assign

value to a variable
Beware not used this “==“ be cause it is
equality operator it checks the equality
between variable name and value assigned to
it.
Syntax will be
Data type variable name assignment
operator value

Variable Names
It is up to you what name you give to your variables
For examples
Int number=10;
First DATA TYPE is INT as it only accept integer which is

10
Second name of our variable is NUMBER name could be
anything here I used Number you can use your name
also
Third Assignment operator we give our variable
Number a value so after this
Number=10 our variable number can store an integer
number 10.

Some Examples
Int number=10;
Int bob=20;
Int khan=30;
Float num=10.87;
Float numbe=10.8;
Double num1=10.2321;
Double khan=10.43434;

Some Examples
Char
Char
Char
Char
Char

name=‘c’;
ali=‘d’;
sign=‘+’;
bob=‘-’
mult=‘*’;

Note(we will discuss strings later it is also a

data type i will create full slides on strings)

Key Points For Char
Char variable can be of 1 byte means it

contain only only character
Char name=‘d’; TRUE
Char name=‘d+’ FALSE
Char sign=‘++’ FALSE
Char sign=‘+’ True
Always use this ‘’ for values

Comments
Always use comments it is good programming

pratice
The benefit of commenting is that some one
who sees your code can easily understand it
For comments use
//this is my prog//
Compiler can execute your programme line by
line and ignore the comments line it does not
effect your programme performance
Use //I am a commnet//

Simple Example
In C++
 #include<iostream>
 using namespace std;
 int main()
{
 int

number=10,number1=20,add;//in
itialize variable and assign
values//
 add=number+number1;//result of
these will be stored in add//
 cout<<add;//for displaying//
}
 Thanks to Devc++

In Java
 public class JavaApplication6 {

/**
* @param args the command line
arguments

*/
 public static void main(String[] args) {

int number=10,number1=20,add;

add=number+number1;

System.out.println(add);
 }


}
 Thanks to netbeans

Thanks alot
Contact me at
muhammadhaseeb562@g
mail.com
Mobile no:0336-5686312