Header File in C++ - learnit

Home Top Ad

Post Top Ad

Friday, August 7, 2020

Header File in C++

Header files in C/C++ Programming

Header files in C/C++ Programming

    C language has numerous libraries that include predefined functions to make programming easier. In C language, header files contain the set of predefined standard library functions. Your request to use a header file in your program by including it with the C preprocessing directive “#include”. All the header file have a ‘.h’ an extension. By including a header file, we can use its contents in our program.


    C language has numerous libraries that include predefined functions to make programming easier. In C language, header files contain the set of predefined standard library functions. Your request to use a header file in your program by including it with the C preprocessing directive “#include”. All the header file have a ‘.h’ an extension. By including a header file, we can use its contents in our program.


1.Function definitions

2.Data type definitions

3.Marcos


    When C++ was first created, all of the files in the standard runtime library ended in array2.h suffix. Life was consistent, and it was good. The original version of COUT and CIN were declared in iostream.h When the language was standardized by the ANSI committee, they decided to move all of the functionality in the standard library into the std namespace to help avoid naming conflicts with user-defined identifies. However, this presented a problem: if they moved all the functionality into the std namespace, none of the old programs (that included iostream.h) would work anymore!


    It offers the above features by importing them into the program with the help of a preprocessor directive “#include”. These preprocessor directives are used for instructing compiler that these files need to be processed before compilation.


    In C program should necessarily contain the header file which stands for standard input and output used to take input with the help of scanf() and printf() function respectively.


In C++ program has the header file which stands for input and output stream and Cin and Cout respectively There are of 2 types of header files


1.Pre-existing header files: Files which are already available in C/C++ compiler we just need to import them.

2.User-defined header files: These files are defined by the user and can be imported using “#include”.


Syntax

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

Write your own C/C++ code and save that file with “.h” extension. Below is the illustration of header file:

#include<iostream>
using namespace std;
class marray{
public: multarray(){
int array[2][4]={
{4,4,3,3},
{10,20,30,40},};
int r,c;
for (r=0;r<2;r++){
for (c=0;c<4;c++)
{
cout <<"Array" <<"[" <<r <<"]" <<"[" <<c <<"]"<<array[r][c]<<endl;}}};

Note Header Files is Name (array2.h)


Include Header File Name(array2.h> is Below

#include "array2.h"
int main()
{
marray obj;
obj.multarray();
}

Please Watching My Video is Below

No comments:

Post a Comment

Post Top Ad