C++ Tutorial № 2 : Variables. Types. Boolean type.

   Hi everyone. It is Bright77 and today we are going to talk about variables: what is variable, how we should declare it and how to operate with them.    First of all we need to give a definition of term “variable”. You can say that variable it is thing that should change. It is quite right, but… So, in C++ you can imagine variable like a special container to store the information we need in the current program in the current time. Variables can store different information: from integer values to sentences and texts. As a conclusion variables can be different types. Types of variables The main types of variables in C++ are :
  1. Boolean type
  2. Character type
  3. Integer types
  4. Floating-point types
   Also the user can define such types as “enum” type, which is used to enumerate the specific set of values. Among them user can use such types as:
  1. Pointer types
  2. Array types
  3. Reference types
  4. Data structures and classes
These types we can separate in some groups of types:    Integral types – in this set we can put boolean type, character type and integer type. Combining integral types and floating-point types we get group called arithmetic types. Enumerations and classes are in the group called user-defined types.    So let`s get started from Boolean type. Boolean type    This type represents the result of logical operations. It can have only two values true or false. Declaration below:
  1. bool c; //declaring variable of type bool without the value
  2. bool a = true; //boolean variable with value "true"
    Also there is a little trick in C++ - if you declare boolean variable with non-zero int value it become "true", with zero value - "false". Code below shows it.
  1. bool x = 2; //x become "true"
  2. bool y = 0; //y become "false"
   So, thats all for today. In the next tutorial we will talk about other types such as character type, integer types, floating-point types. If any questions - post them. See you later :)

Add new comment