Wednesday 6 July 2016

Elements of programming-2



constants:
constants are also memory locations like variables but their values that can not be changed through out the program. only initial assignment is considered. most of the programming languages use const keyword to define constant.
Example:
const float PI=3.14;
some language also # define keyword to define a constant
Datatypes:
when we declare a variable at first time we should tell the compiler what type of data we are going to store.
it may be integer, floating point numbers or char. advanced language also have string type. following are thre primarydata types:
int
float
double
char:

int:
int means integer which indirectly means whole numbers. usually c,c++ int data type takes 2 bytes of memory. but modern c,c++ and alsoc#,java ,vb.net take 4 bytes of memory. modified long int data type take 8 bytes of memory in all modern languages.
float & double:
both are used to store floating point numbers.float data types takes only 4 bytes. double data type takes 8 bytes memory.if you want accuracy you are recommended to choose double data type.
char:
it takes 2 bytes of memory in java & c# because it follows unicode method to store data. it can store only one character .some basic languages uses array of characters to store more than one character.char data type is actually treated internally as char data type.
String:
modern languages like java and c# uses string data type to store more than one character. while char type data are put in to single quotes, string datas are put into double quotes

                                              To  be continued (muthu karthikeyan, madurai)