constants in c.....
constants so that we use to define some fixed values like suppose um value of pi so you will write hash define pi is 3.14 this is what that definition section we have discussed when we were discussing structure of a c program so the value of pi is fixed 3.14 it is symbolic constant if you write hash define suppose max value is 50. so the value of that max is what is to be 50 throughout the program it is not going to be change you cannot change that value these are symbolic constants right so we are having basically two types of constants in c
1] numeric constants
2] character constants
or somewhere it is also written four types of
1] constant integer
2] floating point constant
3] character constant
4]string constant
let us discuss so these are four types of constant or you can say two types numeric and character constant is numeric is further divided into two types integer constant and real constant of floating constant here single character constant string constant so basically four types so let us discuss first one is integer constants these are having decimal values like if you write this uh 10 it is it is a constant five integer constant one integer constant integer constant right these are valid but if you write 0 5 this is not you can say decimal constant see in integer also we have 3 types decimal constant octal constant and hexadecimal constraint right decimal means we can use uh the the numbers from 0 to 9 base is 10 octal constant means from 0 to 7 base is 8 and hexadecimal means we can use from 0 to 15 and bases base of these constants are 16 so integer also having three categories so if you write 0 5 that comes under ah octal constant because the rule is what octal constants starts with the value 0 always right but decimal constant means yeah you can use 0 but if there are two digit in that constant so 0 can be at this side right side but 0 cannot be at this side left side if you write like this this comes under category octal constant right and constants are also called literals right so here also you can we can express an integer in three forms decimal octal and hexadecimal and by default if we say integer constant generally by default we represent that in decimal constant not octal not hexadecimal right difference i have told you what is octal now how you write hexadecimal constant c in hexadecimal we have sequence of digits preceded by either 0 x or you can say 0 small x
let us suppose i write ah 0 x this is what hexadecimal constant right and see in hexadecimal we use what from 0 to 9 numbers and a to f characters i have told i have written here 0 to 15 but here we use from 0 to9 numbers 10 numbers like right and after that 5 is what alphabets a to f right.
so here you can say a means 10 0 to 9 we use numbers 10 numbers then b like this we are having from 0 to 15 0 to 9 numbers and then 10 to 15 we represent like abcdef so if i write 0x that is also exactly decimal constant if i write like 0 x and 7 If this is also hexadecimal constant but if you write 0 x and suppose i am i am writing 7 g this is not hexadecimal constant because we cannot use g we can use only a to f right so you can say these integer constants are sequence of digits suppose i am writing here one two three four this is also what integer constant but rule or what you cannot write like this 56 comma 100 you cannot write any comma or special character between these constants so this is not valid this is invalid constant integer constant right or if and by default the sign is what plus you can also use sine plus or by default x plus if i write minus 1 to 3 this is also valid so you can write a sign either minus 1 plus if you write like this dollar one two three this is incorrect you cannot use any special character you can you you cannot use any comma you cannot use any spacel ike fifty seven space hundred this is also invalid you cannot use space uh between these sequence of digits this there should not be any space any commas any special character this is valid one two three four or like 56 or five six seven eight this is also valid right so now i hope you got integer constant let us discuss real constants so real constants are also known as floating point constants these are having fractional part like if you uh write 12.56 this is decimal part this is you can say you can say this is what the integer part this is decimal point and this is fractional part so having decimal point these are what real constants so if i write plus this that is also fine if i write minus 50 . 6.02 that is also fine sine can be plus or minus by default sign is plus right but if you write this is invalid there cannot be two decimal points right and you can also represent these uh decimal points or these floating point constant in uh exponential form having mantissa then e then exponent mantissa can be anything like having that decimal point and exponent is always constant right so these are some examples see which one is valid constant or numeric constant or not this one is valid 0x this is also valid This is not valid this one this is not valid because here we have space 0 1 2 this is valid 1 2 3 yes this is valid right and if suppose i write 0x af this is also valid and suppose if I write hash one two three this is invalid you cannot use any special character or known digit character right so these are numeric constant.
कोई टिप्पणी नहीं:
एक टिप्पणी भेजें