constants in c
Let us discuss now character constraints these are also two types single character and string string constant what is single character constants if i write like suppose single character is a so you will write like this in single quotation so this is what character constant constant so you can say character constant is what it is having a single character enclosed within single quote marks this is character constant this is also character constant and suppose i write this backslash this one zero this is also character constant these are backs backslash character constraints these are having different meanings there is list of backslash character constants right those are having different meanings fine and you can say like if you write this one comma this is also character constant right and if you write this at the rate this is also character constant so any single character which is enclosed within these single quotation mark within this you can also write down some characters also like a b c d capital a b c d or some numbers and some special characters also those are character constraints and these character constraints are within computer it these are being stored in the form of sky codes right like uh here this a means 97 capital a means what 65 like this small b means 98 and like this capital b means 66 and like this so on right and these are also having uh their different this this value this is also character constant if you write 1 and see 5 is not equal to this 5 this is character constant it is having some different value this is numeric constant this you need to take care right if you are writing anything between these single quotes the number then that is character constant that is not numeric constant this is not integer constant fine so sky value i am writing here you can see so these are sky values capital a to z 65 to 90 small a to z 97 to 122 zero to nine numbers are having a sky value 48 to 57 and some special character like this um coma or at the rate or some special characters are having values from 0 to 47 then 58 to 64 and 91 to 96 right you can also check out like which special character is having between these lie between these values and between these and between these you can google it out right but you have to take care of this thing and you can also perform some arithmetic operations on these character constants right suppose i am printing uh thissee if you are writing like this percentage printf percentage d this is for integer format specifier and a it is what single quote mark so this is what character constant so it will print what integer value of this a because i am writing here format specifier percentage d this is for integer this is to print integer value right here if you compiler will find it is percentage d then it will print what whatever is given here after this coma the first one the first one for that it will print the decimal value means that that integer value the integer value of a is 97 so it will print 97 and if you write percentage c it is what character constant it is used to print characters and if you write here 97 then it will print the equivalent value character value of this 97 fine and see every character is having integer value that is why i am saying that you can also perform arithmetic operations on character constants right next comes to string constant so string constants are you can say sequence of characters enclosed within double
characters and enclosed within double quote mark so this is string constant if you write abc this is what string constant and these characters may be letters number some special characters space everything if i write like uh here a b dollar this is also string constant but here c one thing if i write a in double quote this is not it is single character but enclosed in double quotation mark so it is not character single character constant it is a string constant and if i write a this is what single character constant but these are not equal this is different thing this is different thing this you need to take care this is string constant this is what character single character constant fine and if i write like 1 2 3 4 5 in double quote this is also string constant right but here this like 1 is not equal to this one because this is single character and it is equivalent to its sky value of 1 is 49 but string constant this is not equal to its sky value this is string constant right so you need to take care of this thing also and whenever this string constant is there in a program and when compiler read this string constant then what compiler will do compiler will store the address of the first character reads the address of the first character and it will append a null character constant it will append a null character constant at last why so just to mark this is end of the screw end of this string right so length of the string is what one two three four five six here if you find out the length of this string then it is not five it should be six because a compiler has added null character just to mark that this is end of this string fine so now let us discuss how to declare constants in your program we use what keyword const keyword to declare constant like this right one method is this one so if you write in a program suppose i am writing a function word main i am not writing a complete program you can include those header files and i am writing here const int a value is 10 in this program right means this value of a is constant throughout the program you cannot change this value if suppose you will print this value a then always the output would be 10 and suppose after that i am writing a is equal to 50. you are trying to change the value of a then it this line will give error that this value is you can say its read only value you cannot change this value because you have written conest keyword before this declaration before this initialization of this variable this is variable name that also will discuss what are variables in c this is data type but if you write like this into a is equal to 10 fine when you will print value of a 10 would be printed but after that anywhere in a program you can change this value if you write a is equal to 50 and then if you print value of a then the updated value would be printed 50 now you can change this value this will not give error so you have to declare constant using const keyword right another thing it that i have discussed in starting of this video you can use hash define macro definition symbolic constant so there you can write this would be above this main although you can use anywhere the hash define statement but generally we use where above this main function right so we write like what hash define suppose i am writing a 10 this is also fine right but generally here we write what capital uh letters only like if you're writing pi then pi also if you write max then max also like this right and why i am using these capital letters so that you can distinguish between the normal variables within the programs and the symbolic constraints that is why there are some rules when you use this hash define statement then there are some rules to write this the statements and what are those rules there should not be any space between hash and define there should also be a space between hash define this and then name of that constant and then value of that constant another thing you cannot use here equal to right this would be wrong fine you cannot use semicolon after a statement.
कोई टिप्पणी नहीं:
एक टिप्पणी भेजें