Documenting my CPP Journey Part #3
Published: 2023-03-26 15:44:11

---
title: Documenting my CPP Journey Part #3
published: true
date: 2022-12-03 04:06:39 UTC
tags: 
canonical_url: https://theamazingatharva.hashnode.dev/documenting-my-cpp-journey-part-3
---

# **Introduction :**

Welcome to my first series on #Hashnode where I will be documenting my journey of learning C++ **from scratch to advance** to develop my programming skills and later make some **interesting projects**. In this blog, I will be sharing what I learnt in C++ since I wrote my [previous blog](https://dev.to/atharva_salitri/documenting-my-cpp-journey-part2-53dl-temp-slug-2530910) . In this tutorial, we can study the **Data Types, Basic Input/Output, header files and Operators** withinside the C++ language. In our last lesson, I mentioned the different variables (their syntax and types), and comments in a C++ program. **Do check it out** to be up to date with what I will be sharing in this one.

# Data Types :

All variables use data type during declaration to restrict the type of data to be stored. Therefore, we can say that data types are used to tell the variables the type of data they can store. Whenever a variable is defined in C++, the compiler allocates some memory for that variable based on the data type with which it is declared. Every data type requires a different amount of memory.

### **C++ supports the following data types:**

1. **Primary or Built-in or Fundamental data type** : These data types are built-in or predefined data types and can be used directly by the user to declare variables. example: int, char, float, bool, etc.

2. **Derived data types** : Derived data types that are derived from the primitive or built-in datatypes are referred to as Derived Data Types like Function, Array etc

3. **User-defined data types** : These data types are defined by the user itself. For example class, structure, enum etc.

In this blog, we will be focusing on Primitive Data Types.

# Primitive Data Types

- **Integer** : The keyword used for integer data types is **int**. Integers typically require 4 bytes of memory space and range from -2147483648 to 2147483647.

- **Character** : Character data type is used for storing characters. The keyword used for the character data type is **char**. Characters typically require 1 byte of memory space and range from -128 to 127 or 0 to 255.

- **Boolean** : Boolean data type is used for storing Boolean or logical values. A Boolean variable can store either _true_ or _false_. The keyword used for the Boolean data type is **bool**.

- **Floating Point** : Floating Point data type is used for storing single-precision floating-point values or decimal values. The keyword used for the floating-point data type is **float**. Float variables typically require 4 bytes of memory space.

- **Double Floating Point** : Double Floating Point data type is used for storing double-precision floating-point values or decimal values. The keyword used for the double floating-point data type is **double**. Double variables typically require 8 bytes of memory space.

- **void** : Void means without any value. void data type represents a valueless entity. A void data type is used for those function which does not return a value.

# **Basic Input and Output in C++**

C++ language comes with different libraries, which help us in performing input/output operations. In C++ sequences of bytes corresponding to input and output are commonly known as streams. There are two types of streams:

1. **Input Stream:** If the direction of flow of bytes is from the device(for example, Keyboard) to the main memory then this process is called input.

2. **Output Stream:** If the direction of flow of bytes is opposite, i.e. from main memory to device( display screen ) then this process is called output.

## **Header files available in C++ for Input/Output operations are:**

_What Are C++ Header Files_? These are **those files that store predefined functions**. It contains definitions of functions that you can include or import using a preprocessor directive #include. This preprocessor directive tells the compiler that the header file needs to be processed prior to the compilation.

**<mark>iostream</mark>** : iostream stands for standard input-output stream. This header file contains definitions of objects like **cin, cout, cerr,** etc. The two instances **cout in C++** and **cin in C++** of iostream class are used very often for printing outputs and taking inputs respectively. These two are the most basic methods of taking input and printing output in C++. To use cin and cout in C++ one must include the header file _iostream_ in the program.

- **Standard output stream (cout)**: Usually the standard output device is the display screen. It is used to produce output on the standard output device which is usually the display screen. The data needed to be displayed on the screen is inserted in the standard output stream (cout) using the insertion operator( **<<** ).

- **standard input stream (cin)**: Usually the input device in a computer is the keyboard. C++ cin statement is used to read input from the standard input device which is usually a keyboard. The extraction operator( **>>** ) is used along with the object **cin** for reading inputs. The extraction operator extracts the data from the object **cin** which is entered using the keyboard.

```
#include <iostream>
using namespace std;

int main()
{
    int a; //integer data type
    cout<<"Enter a number \n"; //output stream
    cin>>a; //input stream
    cout <<"Value of a is = "<<a;
    return 0;
}

```

# Operators :

An operator is a symbol that tells the compiler to perform specific mathematical or logical manipulations. C++ is rich in built-in operators and provides the following types of operators

- **Arithmetic Operators** : These operators are used to perform arithmetic or mathematical operations on the operands. For example, **+ is used for addition** , **- is used for subtraction \* is used for multiplication,** etc.

- **Relational Operators** : These operators are used for the comparison of the values of two operands. For example, > checks if one operand is greater than the other operand or not, etc. The result returns a **Boolean** value, i.e., **true** or **false.**

- **Logical Operators** : These operators are used to combine two or more conditions or constraints or to complement the evaluation of the original condition in consideration. The result returns a Boolean value, i.e., **true** or **false**. Eg.

- **Bitwise Operators** : These operators are used to perform bit-level operations on the operands. The operators are first converted to bit-level and then the calculation is performed on the operands

- **Assignment Operators** : These operators are used to assign value to a variable. The left side operand of the assignment operator is a variable and the right side operand of the assignment operator is a value. The value on the right side must be of the same data type as the variable on the left side otherwise the compiler will raise an error.

# Congratulations!

### You just learnt about Header files, Basic Input/Output and Operators in C++ !!!

Thank you for joining me in my quest to conquer C++. In the next blog, well be talking more about the different control statements in a C++ program, see you there, till then keep coding and keep learning.

# Credit To The Following Resource I Referenced :

1. w3schools

2. [geeksforgeeks](https://www.geeksforgeeks.org/)