Posts

Showing posts from September, 2022

Input / Output in C++

Preprocessor Directive -  Used to include files. Ex: #include. There are some files in C++ that are used for a specific purpose. Ex: #include<iostream> is used for taking input and printing output. The execution of the code begins from the main function. It is mandatory for any program. Ex: int main().  "cout" is used to display output that is in quotation marks. Ex: cout<<"Hello World";. It will display the output as Hello World . return 0 is important to specify. It marks the end of the function. That means now you can get out of the function. So, we can say that it is the exit status of the function. {}, the curly braces indicate the start and end of a function. Sample Program: #include <iostream> using namespace std ; int main (){     cout << "Hello World \n " ;     return 0 ; } Output: Hello World                                                                                   

Data Types and Modifiers

Data Types Primitive - Integer, Float, Character, Boolean Derived - Function, Array, Pointer, Reference User Defined - Class, Structure, Union, Enum Examples for Primitive Data types: Integer - 1, 4, 100 Float - 3.14, 5.22, 4.243432 Character - @, |, c, f Boolean - True, False or (0, 1) Integer occupies 4 bytes. Since 1 Byte = 8 bits, integer occupies 32 bits in a memory. Range of unsigned integer is 0 to (2^32)-1. To store negative integer, the left most (most significant bit [MSB]) is used to define the sign of the integer. So, if the left most bit is filled with 1, it means that the integer is negative and if it is 0, then it is a positive integer. Therefore, the range of signed integer is -(2^31) to (2^31)-1. Float occupies 4 bytes. We can store up to 7 decimal digits. If we want to store more digits, then we use another data type called Double that occupies 8 bytes. It can store up to 15 decimal digits. Char occupies 1 byte. We use ASCII table that is attached below. Boolean data