Integer Constant in C++

Q3. How many ways are there in C++ to represent an integer constant?

Ans. In C++, an integer constant can be represented in 3 ways:

  1. As a decimal integer constant in which the integer constant consists of a sequence of digit but it does not begin with digit 0 (zero). For example, 1234 is a decimal integer constant but 01234 is not a decimal integer constant.
  2. As an octal integer constant in which the integer constant begins with digit 0 (zero). For example, 9 (in decimal) can be written as 011 (octal equivalent of 9) as octal integer.
  3. As a hexadecimal integer constant in which the integer begins with ox or OX. For instance, 11 (in decimal) can be written as OXB (hexadecimal equivalent of 11).

Leave a Reply

Your email address will not be published. Required fields are marked *

%d bloggers like this: