0

What is constants??

9th Apr 2019, 11:48 AM
Gaurav Rawat
Gaurav Rawat - avatar
3 odpowiedzi
+ 8
Once you have defined a variable constant it means it cannont be modified the correct way to define one is const int var = 42; var+=10; //see here i am trying to directly change the value of var doing this will throw an error.
9th Apr 2019, 11:59 AM
D_Stark
D_Stark - avatar
+ 3
Constants are those which do not change their value. we can either use the const keyword or #define preprocessor directive to declare constants. For example: const int x=8; x++; printf("%d",x); In this case, u will get a compilation error. Same is the case with #define Syntax: #define x 8 Variables can change their value. For example: int x=2; x++; printf("%d",x); The output in this case will be 3. For more details : https://www.google.com/amp/s/www.geeksforgeeks.org/constants-in-c/amp/ Hope u understand it better now.
9th Apr 2019, 12:07 PM
@$@$!Π
@$@$!Π - avatar
+ 1
Constants are always their initial value. X=1 as a constant X will always = 1 The value of X can not be manipulated. As a variable, the value of X can be manipulated. X=1, Y=2, X=X+Y X now is X=3
9th Apr 2019, 1:01 PM
Michael Williams
Michael Williams - avatar