In contrast to the variable whose contents can change during the execution of the program while the contents of the constants can not be changed.
Constants are fixed values that are similar to variable declaration, its value only course that can not be changed.
There are two ways to declare the constants:
- After the declaration header file using # define
- In the function by using the const
/ / declare constant
# include <iostream>
# include <conio.h>
# define phi 3:14
# define r1 3
# define r2 10.7
# define kar 'A'
# define the text "Examples of constant declarations"
# define x true
main () {
/ / calling constants
court <<text <<"\ n";
court <<kar <<"\ n";
court <<x <<"\ n";
court <<pi <<"\ n";
court <<r1 <<"\ n";
court <<r2 <<"\ n";
getch ();}
Constants are fixed values that are similar to variable declaration, its value only course that can not be changed.
There are two ways to declare the constants:
- After the declaration header file using # define
- In the function by using the const
/ / declare constant
# include <iostream>
# include <conio.h>
# define phi 3:14
# define r1 3
# define r2 10.7
# define kar 'A'
# define the text "Examples of constant declarations"
# define x true
main () {
/ / calling constants
court <<text <<"\ n";
court <<kar <<"\ n";
court <<x <<"\ n";
court <<pi <<"\ n";
court <<r1 <<"\ n";
court <<r2 <<"\ n";
getch ();}
No comments:
Post a Comment