"If there are any images please click on them to get a clear picture of that"
There are certain rules we should follow to use a variable in our program:
- It can have numbers,digits.
- Should not contain spaces between 2 words but we can append them using underscore. Ex:-Hello_world.......correct way. Hello world........wrong way.
- Never start with a digit.
- They are case sensitive which means A and a are not same. Ex:- int HeLLo_World=256; int Hello_World=341; So if we print HeLLo_World then the output is 256 and if we print Hello_World then the output is 341.
It is because we know that both give same meaning but compilers are not having natural intelligence like us.They will take as input what ever we give to them.They don't see the meaning of a variable. so,that is why it consider both of them as differently.When ever we declare variables we should think from the side of compiler.
In every program we use data types.
Data types are of 3 types:-
1.User defined data types such as structures,functions etc.
2.Built in data types such as int,float,char,double etc.
3.Derived datatypes such as arrays and pointers
1.int :-represents integer type i.e if we declare as Ex:-int a then a should contain only integer values.
2.float:-represents decimal values. Ex:- float a means a can take values containing decimals.As float a=7.777;
3.double:-the variable here can be an integer containing more range than int or can be of a float type. Ex:- double a; 4.char:-represents character Ex:-char a='A'; if it is a single letter we represent the letter with in single quotes. char a[]="hello" if it is more than one letter then we represent the word with in double quotes. For each data type there are range of values. Ex:-considering a 16 bit compiler int has 2 bytes which means from -32768 to 32767. that is if we declare int a=43555 and printing value of a gives us a garbage value. similarly for every data type they have their range values.
in normal case we use mainly int,float,double, and char. If we use 'char' while printing we should use %c if it is a character in single quotes otherwise %s if it is a word in double quotes.
letter in single quotes are called as characters and those in double quotes they are called as strings.
Ex:-
here I used "\n". It is for going to next line.
output:-
Escape sequences:- \n--new line. \t--a space of tab width. \v--vertical tab.As in the above program we used \n so the output statements are in line by line otherwise the output will be like:-
output:-
No comments:
Post a Comment