5. Introduction to c++: Constants: Basic Programming for Beginners :: Videos



Description:


Topics Covered Here:

 

  • Literal Constants
  • Defined Constants
  • Declared Constants
  • Literal constants

Most easy to see and most obvious constants: Literal Constants.
Types of literal constants:

 

 

  • Integer Numerals: 
    • A number without decimal points (duh!). Examples: 23, 56, 8...
    • In C++, expressing numerical constants does not require any special character like "".
    • Integer numerals can be defined in other numeral forms like octal or hexadecimal.
      • 255 Decimal Value
      • 0377 Octal value
      • 0xff Hexadecimal Value
    • Decimal, Octal, hexadecimal, signed and unsigned representation
      • To denote an octal number(Base 8 number) start the number with 0 (zero)
      • To denote a hexadecimal value(base 16 number) start with 0 x (zero "x")
      • Write normally for decimal numerical(base 10) system value.
      • Force int to be unsigned by adding u(or U) at the end of number. (Ex: 19U) or l(or L) to make it long( 19L or 19UL)

 

  • Floating-Point Numerals: 
    • To represent number with decimal or exponents
    • A decimal point "." or a "e" can be added to represent the number, where e means to the "power by 10" to number after e.
    • Also can have both "e" and "."  Examples:
      • 3.14 (Value of Pi)
      • 5.97e24 (Mass of earth) = 5.97 x 10 ^ 24 or
      • 1.67e-27(Mass of proton) = 1.67 x 10 ^ -27
    • Force number to be long double add L or l, to force number to be float add f or F in the end of the number
    • E or e both are same. C++ is not case sensitive in this case.
  • Boolean literals: 
    • Only two boolean literals in C++: true or false.
    • Can be represented by bool data type.
  • Character literals:
    • Represents only one character. Example: 'a', 'b', 'A' etc...
    • To represent character literals we put them inside single quotes(' '). This is done to differentiate them from possible variable identifiers that we might define in the program.
    • If you just write 1 it is a numerical literal. But '1' makes it character literal.
    • 'a' is a character literal where as just a is a variable identifier named a.
  • String literals: 
    • Combination of characters.
    • Inside double quotes (" ").
    • Example "Dean"
  • Escape Characters
    • Characters and string both can have a special character called escape character.
    • Characters that are impossible or at least difficult to express otherwise
    • Precede by a backslash(\) and the character.
    • Examples:
      • \n (New Line),
      • \t (Tab)
      • '\n' or '\t' or
      • "LineOne\nLineTwo\nLineThree"
      • "\"DoubleQuote\"" = "DoubleQuote" when you print.
    • Few list of escape characters:
      • \n = Newline
      • \t = tab
      • \r = carriage return
      • \v = vertical tab
      • \b = backspace \f = form feed
      • \a = alert beep
      • \' = single quote(')
      • \" = Double quote(")
      • \? = question mark(?)
      • \\ = backslash(\) Defined constants

Thanks for watching the video!!!


Comments:

Please login to post your thoughts!
 

There are no commnets yet!
 

Login

Username:
Password:
Don't have an account?
Register here
Register

Subscribe Youtube



Network DigitalStage.org


Some interesting stuffs