0 votes
in C Plus Plus by
What is a Constant? Explain with an example.

1 Answer

0 votes
by

A constant is an expression that has a fixed value. They can be divided into integer, decimal, floating-point, character or string constants depending on their data type.

Apart from the decimal, C++ also supports two more constants i.e. octal (to the base 8) and hexadecimal (to the base 16) constants.

Examples of Constants:

75 //integer (decimal)

0113 //octal

0x4b //hexadecimal

3.142 //floating point

‘c’ //character constant

“Hello, World” //string constant

Note: When we have to represent a single character, we use single quotes and when we want to define a constant with more than one character, we use double-quotes.

Related questions

0 votes
asked Dec 21, 2023 in C Plus Plus by GeorgeBell
0 votes
asked Aug 11, 2023 in Angular by DavidAnderson
...