How To Start With C++ | HSC CS Maharashtra Board

To start with C++ first we need to download and install the Turbo compiler click here to download . This blog is mainly focused on the students of the HSC board. Here we learn about C++ header files how to start a program and every basic thing about C++.

Hey there, it’s your friendly neighborhood computer engineer, Vinit Pandey! I’m the mastermind behind smmwizardpro.com and edu4maharashtra.in – websites so cool they’ll make your head spin. And if you’re not following me on Instagram at vinit.bro, well, let’s say I am missing you their.

So if you want to level up your tech game, just hit me up. I promise I won’t bite – unless you’re a computer virus, in which case I’ll destroy you faster than you can say “blue screen of death.”
Author Name

What is Header File? and it types

 C++ offers its users a variety of functions, one of which is included in header files. In C++, all the header files may or may not end with the “.h” extension but in C, all the header files must necessarily end with the “.h” extension. 

Syntax: 

#include <filename.h>
or
#include "filename.h"

Types of Header Files in C++

TypeFunction
#include<stdio.h>(Standard input-output header) Used to perform input and output operations in C like scanf() and printf().
#include<iostream>(Input Output Stream) – Used as a stream of Input and Output.
#include<string.h>(String header) Perform string manipulation operations like strlen and strcpy.
#include<conio.h> (Console input-output header) Perform console input and console output operations like clrscr() to clear the screen and getch() to get the character from the keyboard.
#include<stdlib.h>(Standard library header) Perform standard utility functions like dynamic memory allocation, using functions such as malloc() and calloc().

How to start with C++ ?

We start with the #include<iostream> line which essentially tells the compiler to copy the code from the iostream file(used for managing input and output streams) and paste it in our source file.  Header iostream, that allows performing standard input and output operations, such as writing the output of this program to the screen. Lines beginning with a hash sign (#) are directives read and interpreted by what is known as the preprocessor.

We then declare a function called main with the return type of int main() is the entry point of our program. Whenever we run a C++ program, we start with the main function and begin execution from the first line within this function and keep executing each line till we reach the end. We start a block using the curly brace{ here. This marks the beginning of main’s function definition, and the closing brace } its end. All statements between these braces are the function’s body that defines what happens when main is called. Sometimes we use int main(), or sometimes void main(). Now the question comes into our mind, that what are the differences between these two.

The main() function is like other functions. It also takes arguments, and returns some value. One point we have to keep in mind that the program starts executing from this main() function. So the operating system calls this function. When some value is returned from main(), it is returned to operating system. The void main() indicates that the main() function will not return any value, but the int main() indicates that the main() can return integer type data. When our program is simple, and it is not going to terminate before reaching the last line of the code, or the code is error free, then we can use the void main(). But if we want to terminate the program using exit() method, then we have to return some integer values (zero or non-zero). In that situation, the void main() will not work. So it is good practice to use int main() over the void main().

In the end of the program we have to use getch();
The getch(); is a predefined non-standard function that is defined in conio.h header file. It is mostly used by the Dev C/C++, MS- DOS’s compilers like Turbo C to hold the screen until the user passes a single value to exit from the console screen. It can also be used to read a single byte character or string from the keyboard and then print. It does not hold any parameters. It has no buffer area to store the input character in a program.

Let’s see an example program of C++

#include <iostream.h>
#include <conio.h>
void main()
{
     int x=3,y=4;
     if(x<y)
             cout<<"x is greater then y"<<endl;
     else
             cout<<"x is smaller then y"<<endl;
     getch();
}

Leave a Comment

Scroll to Top