#C++ #programming #constants #c_language #programming_languages
welcome back to the series of introduction to computer programming in this video we will discuss about constants in c or c plus plus programming language as the name suggests the name constants are given to such variables or values in c or c plus plus programming language which cannot be modified or changed once they are defined they are fixed values they cannot be changed throughout the execution of the program a constant can be of any data type like integer character float etc now how to define a constant in c or c++ programming language we can define constants in two different ways the first method is by using a constant keyword c-o-n-s-t is the key word for constant we have to write this constant in the main function sentex is constant space data type space the name of constant equals to the value for the constant which we are going to use throughout the execution let's see example if we want to define pi 3.14 or we can write it in our program we are going to start it by hash include iostream then we will write the main function and we have to write it in the main function constant const is the keyword for constant space float it is the data type space pi it is the name of the constant equal to 3.14 which is the value assigned to pi now the value of pi will remain same throughout the execution now coming to the second method by using a # define which is a preprocessor directed we must define it in the very beginning of the program it is because we must write all the preprocessor directives before the global declaration the scientix is # defined it is the preprocessor space name of the constant space value now how we are going to use in a computer program hash include iostream now comes the preprocessor here # define pi space 3.14 now the main function comes integer main in the main function we are using if we are using pi the value is 3.14 and it cannot be changed throughout execution
Constants in C/C++ As the name suggests the name constants are given to such variables or values in C/C++ programming language which cannot be modified once they are defined. They are fixed values in a program. There can be any types of constants like integer, float, octal, hexadecimal, character constants, etc.
0:28
which cannot be modified or changed
once they are defined they are fixed
values they cannot be changed throughout
the execution of the program
a constant can be of any data type like
integer character float etc