comment 0

Basic of C/C++ – Day 2

Types, Operators and Expressions

  • Variables and constants are the basic data object manipulated in a program.
  • Expressions combine variables and constants to produce new values.
  • All variables must be declared before they are used, usually at the begining of the function before any executable statements.

Variable Names

  • Variable names can made up of letters and digits.
  • Traditional C practice is to use lower case for variable names, and all upper case for symbolic constants.

Data Types and Sizes

  • char a single byte, capable of holding one character in the local character set.
  • int an integer, typically reflecting the natural size of integers on the host machine.
  • float single-precision floating point.
    double double-precesion floating point.


  • Constants are expressions with a fixed value
  • The types :
    • Literal
    • Defined constant
    • Declared constant


  • Literals are used to express particular values within the source code of a program.
  • Example : r = 69
    the 69 in this piece of code was a literal constant.
  • Literal constants can be divided in Integer Numerals, Floating-Point Numerals, Characters, Strings and Boolean Values.

Defined Constant

  • We can define your own names for constants that you use very often without having to resort to memory consuming variables, simply by using the #define preprocessor directive
  • The format :
    #define identifier value
  • Example :
    #define Phi 1.618
    #define pi 3.14159

Declared Constant

  • With the const prefix you can declare constants with a specific type in the smae way as you would do with a variable.
  • Example :
    const int damage = 666;
    const char tabulator = '\t';
  • It will treated just like regular variables except that their values can’t be modified after their definition.

Filed under: C++

Leave a Reply

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