Programming for Problem Solving (3110003)

BE | Semester-1   Winter-2019 | 07-01-2020

Q3) (a)

Explain different types of constants.

Constant is something whose value does not change throughout the program.

Integer Constant

Integer constant is a number without decimal point and fractional part.
There are three types of integers constant.
 
  1. Decimal integer: Decimal integers consist of a set of digits, 0 to 9 having optional – or + sign. No other characters are allowed like space, commas, and non-digit characters.
    Ex: 123, -321, 0, +78
  2. Octal integer: Octal integer consists of any combination of digits from the set 0 to 7. Octal numbers are always preceded by 0.
    Ex: 037, 0, 0551
  3. Hexadecimal integer: Hexadecimal integer consists of any combination of digits from the set 0 to 9 and A to F alphabets. It always starts with 0x or 0X. A represents 10, B represents 11... F represents 15.
    Ex: 0X2A, 0x95, 0xA47C
 

Real constant

The number containing the fractional part is called the real number. A real number may also be expressed in exponential notation. The general form is: mantissa e exponent, ex: 215.65 can be written as 2.1565e2. 2 In exponential form, e2 means multiply by 10. 0.0083, -0.75, +247.0, -0.75.

Single character Constant

It contains a single character enclosed within a pair of single quote marks. E.g.: ‘5’, ‘A’, ‘;’, ‘ ‘ .

String Constant

A string constant is a sequence of characters enclosed within a double inverted comma. The characters may be letter, number, special character, blank space, etc... “DIET”, “1988”, “?A.B,!”, “5+3”, etc... . ‘A’ is character but “A” is string.