3rd day
programming :
Task:
Your task is to print
your name , phone number , address on the console screen(the executional black)
all the data will be in separate lines .
you got 4 minutes for it.??
e.g
M Shafay Amjad
0XXXXXXXXXX
Lahore,Pakistan
Hint: Use cout<< statement;
And endl; for next line .
If you have done this task you have learn the previous day
lecture very well.
Now today what we are going to do is that we will learn
about what are variables, datatypes;
Datatypes:
as we all know that the data is in different forms .
1) Data can be of
Int (Integer type) which is
in form of integer,its high form is double having supporting more numeric value
>2e32. J
2) Data could be
in the form of decimal notation such as a Float(decimal
pointed value) like 3.145 ,0.25 etc.
3) Data could be a char
(in form of characters )type
e.g a,b,c,d etc
4) Data could be string type(in form of a
string )(in easy word combinations of character,numbers) e.g
e.g Shafay ,Charlie Harper , 12shafay90 ,
HarpersFamily1999. Etc
Our today’s topic Is to know about data type and how to
declare(means create them in our program )
First Objective:
Declaring a Datatype.
To declare an Integer type , In the main() function (where
everything of your programing code is written )
Writing:Symbol:
Datatypename Variablename;
Here Datatype is of(Int or float or char or string),
while Variable name is (The name you assign to that data type )
e.g:
int no1;
float number;
char ch;
string name;
Here (int,float,string,char) are datatypes and no1,number,ch,name are variable name
given by us to the code ,which is to be compiled by programming language.
Intializing
datatypes:
To Intialize you data type you need to use an
assignment operator i.e( = ) ,
In programming you use
For
int,float,double
Datatype Variablename= value;
e.g:
for Int,Float:
int no=10;
float num=15;
here as you can see the assignment operator assigns
the right numeric value to the left side of the variable name .
so Your second Program is going to be declaring and
initializing a Int ,and a float Variable.
After executing
You can see in your program the two type of data being declared and initialized , with there respective variable names (num,no).
Output:
TO print the output , you use the cout statement after that << operational and after that it is followed by the variable name .
Concept: the basic concept of programming declaration is that ,when you declare a variable it assgn that variable their respective byte as in case of int it allocate (4 byte) data double(8 byte datq)
char 1 byte data , Boolean (1 byte data and others ).
the thing should be kept in mind that the value entered /assigned to the variable should be of its data types, Unless this you will project to an error or miscalculation .
Basic Error or Flaws by Beginners while declaring:
e.g: int no=10.5;
cout<<no;
as you can see we have assign the basic int variable a value , but what we didnt see coming is that instead of outputing 10.5, it outputs 10.
its because of the data type you given it ignores the pointed value after and takes the value perior to the decimal value().
pointed value .
in case of char
type :
char
variablename= ‘a’;
here all the value rather you assign form (a-z) in
char type is assigned right after (=) sign in the single quotes (‘’) which represent
it is a character type . The most important thing is that a char
type is not a character type formed infact it is an Int type as a computer
understand a Machine code , and that Machine code is given to computer in the
form of ASCII(American Standard computer Instruction…. Whatever ) .
what we didn't knew that the char datatype can also hold datas like '\a' for a beep, '\r' for the enter button e.t.c. It a basic question of programming about char as it can hold data in backslash also,
the question arises how ?
Actually there is the thing that a data is to be given in form of ASCII and in ASCII there is a specific Int combination for the combined word like (\r for enter , \a for beep ),
so you can also use these specific buttons using char type .
in case of a String :
Declaration & Initialization of String:
String name="shafay";
Remember the value is assign to the string in the double quotes :)
so you can also use these specific buttons using char type .
in case of a String :
Declaration & Initialization of String:
String name="shafay";
Remember the value is assign to the string in the double quotes :)
No comments:
Post a Comment