•Constants are expressions with fixed
values while literals are used to
express a particular value within the
source code of a program.
Example: number = 5
This example is a literal constant
1. Integer Literals
2. Floating point Literals
3. Boolean Literals
4. Character Literals
It may be in decimal, octal, or hexadecimal constant.
To specify the base or radix; Ox or OX for
hexadecimal, O for octal, and none for decimal. Also,
integer literals can have a suffix of U and L for
unsigned and long integer. The suffix can be written
in uppercase or lowercase and in any order.
• 312 //legal
• 212u //legal
• Oxace //legal
• O79 //illegal: 9 is not an octal number
• O42UU //illegal: suffix should not be
repeated
1. 15
Answer: Legal
2. O18
Answer: Illegal,8 is not an octal number.
3. Ox38a
Answer: Legal
4. O33UU
Answer: Illegal, Suffix should not be repeated.
5. O24
Answer: Legal
• 75 //decimal
• O712 //octal
• Ox5C //hexadecimal
• 2O //int
• 2Ou //unsigned int
• 2Ol //long
• 2Oul //unsigned long
1. 15
Answer: Decimal
2. O335
Answer: Octal
3. Ox38a
Answer: Hexadecimal
4. 9Ol
Answer: Long int
5. 9Ou
Answer: Unsigned int
• It is composed of an integer, a decimal point, a fraction.
And an exponent. It can be represented either in decimal
form or exponential form.
• Floating point in a decimal form should have a decimal
point and exponent, while in the exponential form, you
should include the integer part, the fractional part, or
both. The signed exponent is written as e or E.
• 3.1416 //legal
• 314159E-5 //legal
• 41OE //illegal: no exponent
• 31Of //illegal: no decimal or exponent
• .e33 //illegal: missing integer or fraction
1. 10.125
Answer: Legal
2. 5E-3
Answer: Legal
3. 123E
Answer: illegal, no exponent
4. 0.E879
Answer: illegal, missing integer or fraction
5. 105E-3
Answer: Legal
This are part of the standard keyword of C++.
•True value represents TRUE.
•False value represents FALSE.
It should be enclosed in single quotes. There
are characters in C++ that include a backslash
() that specifies a special meaning or function.
•  character
• ’ ‘character
• ” “character
• ? ?character
• a Alert or bell
• b Backspace
• f Form Feed
• n New line
• r Carriage return
• t Horizontal tab
• v Vertical tab
• ooo Octal number of one to three
digits
• xhh Hexadecimal no. of 1 or more
digits
#include <iostream>
Using namespace std;
Int main () {
cout<<“LovetProgrammingnn”;
return 0;
}
Love Programming
23-24Quarter One-COMPUTER 10-Literals.pptx

23-24Quarter One-COMPUTER 10-Literals.pptx

  • 2.
    •Constants are expressionswith fixed values while literals are used to express a particular value within the source code of a program. Example: number = 5 This example is a literal constant
  • 3.
    1. Integer Literals 2.Floating point Literals 3. Boolean Literals 4. Character Literals
  • 4.
    It may bein decimal, octal, or hexadecimal constant. To specify the base or radix; Ox or OX for hexadecimal, O for octal, and none for decimal. Also, integer literals can have a suffix of U and L for unsigned and long integer. The suffix can be written in uppercase or lowercase and in any order.
  • 5.
    • 312 //legal •212u //legal • Oxace //legal • O79 //illegal: 9 is not an octal number • O42UU //illegal: suffix should not be repeated
  • 6.
    1. 15 Answer: Legal 2.O18 Answer: Illegal,8 is not an octal number. 3. Ox38a Answer: Legal 4. O33UU Answer: Illegal, Suffix should not be repeated. 5. O24 Answer: Legal
  • 7.
    • 75 //decimal •O712 //octal • Ox5C //hexadecimal • 2O //int • 2Ou //unsigned int • 2Ol //long • 2Oul //unsigned long
  • 8.
    1. 15 Answer: Decimal 2.O335 Answer: Octal 3. Ox38a Answer: Hexadecimal 4. 9Ol Answer: Long int 5. 9Ou Answer: Unsigned int
  • 9.
    • It iscomposed of an integer, a decimal point, a fraction. And an exponent. It can be represented either in decimal form or exponential form. • Floating point in a decimal form should have a decimal point and exponent, while in the exponential form, you should include the integer part, the fractional part, or both. The signed exponent is written as e or E.
  • 10.
    • 3.1416 //legal •314159E-5 //legal • 41OE //illegal: no exponent • 31Of //illegal: no decimal or exponent • .e33 //illegal: missing integer or fraction
  • 11.
    1. 10.125 Answer: Legal 2.5E-3 Answer: Legal 3. 123E Answer: illegal, no exponent 4. 0.E879 Answer: illegal, missing integer or fraction 5. 105E-3 Answer: Legal
  • 12.
    This are partof the standard keyword of C++. •True value represents TRUE. •False value represents FALSE.
  • 13.
    It should beenclosed in single quotes. There are characters in C++ that include a backslash () that specifies a special meaning or function.
  • 14.
    • character •’ ‘character • ” “character • ? ?character • a Alert or bell • b Backspace • f Form Feed
  • 15.
    • n Newline • r Carriage return • t Horizontal tab • v Vertical tab • ooo Octal number of one to three digits • xhh Hexadecimal no. of 1 or more digits
  • 16.
    #include <iostream> Using namespacestd; Int main () { cout<<“LovetProgrammingnn”; return 0; }
  • 17.