What is a constant? Explain with an example.



What is a constant? Explain with an example...

Answer / Pratibha Yadav

In C++, a constant is a variable whose value cannot be changed during the execution of the program. It is also known as a literal.nnThere are four types of constants in C++:n1) Integer Constants: Examples include 42, 0xFF (hexadecimal), and 3'000'000 (cube notation).n2) Floating-Point Constants: Examples include 3.14159 (decimal), 6e-7f (exponential notation for floating-point numbers), and 0xf0p-2 (binary floating-point number with mantissa and exponent parts).n3) Character Constants: A character constant is enclosed in single quotes, like 'a' or 't'.n4) String Literals: A string literal is a sequence of characters enclosed in double quotes, like "Hello, World!".nnA const variable can be declared by adding the keyword const before its type. For example, `const int my_constant = 42;`

Is This Answer Correct ?    0 Yes 0 No

Post New Answer

More C++ General Interview Questions

Specify different types of decision control statements?

1 Answers  


What should main() return in c and c++?

1 Answers  


What is the role of C++ shorthand's?

1 Answers   TCS,


Mention the ways in which parameterized can be invoked.

1 Answers  


What is the difference between map and hashmap in c++?

1 Answers  


When one must use recursion function? Mention what happens when recursion functions are declared inline?

1 Answers  


What is jump statement in C++?

1 Answers   Ericsson,


What is virtual destructor? What is its use?

1 Answers  


Write a program to swap 2 chars without using a third varable? char *s = "A"; char *p = "B";

7 Answers   CTS,


Write a single instruction that will store an EVEN random integer between 54 and 212 inclusive in the variable myran. (NOTE only generate EVEN random numbers)

1 Answers  


Explain the concept of memory leak?

1 Answers  


Must accepts "Maestro Cards" Tax for bike should be less than 15 Total number of lanes is more than 10 Must provides monthly pass Write a method: boolean isGoodTollBridge(String[] cardsAccepted, String[] tollTax, boolean hasMonthlyPass, int numberOfLanes); String[] cardsAccepted A String array of names of card types accepted for payment of toll tax, it can be null if the toll does not accept any card String[] tollTax A String array of toll tax chart (say “Train : 300”,”BullCart : 10”) boolean hasMonthlyPass This parameter defines whether there is any monthly pass available or not int numberOfLanes This parameter defines the number of lanes for each side

1 Answers   Telecom,


Categories