Header Files
...

In C++, header files are used to declare functions, classes, variables, and other entities that are defined in other source files. Header files are typically used to share declarations between files and to provide a modular structure for C++ programs.

A header file typically has a .h or .hpp file extension and contains declarations of functions, classes, and other entities that are defined in one or more source files. Here's an example of a simple header file:

#ifndef MY_HEADER_H
#define MY_HEADER_H

int add(int x, int y);

#endif

In this example, MY_HEADER_H is a preprocessor macro that is used to prevent the header file from being included multiple times in the same source file. The add() function is declared in the header file, but its implementation is defined in a separate source file.

To use a header file in a source file, you typically include the header file using the #include directive. For example:

#include "my_header.h"

int main() {
  int result = add(5, 10);
  return 0;
}

In this example, the my_header.h header file is included in the main.cpp source file. This allows the add() function to be called in the main() function.

Header files can also include other header files, which allows for a modular structure in C++ programs. For example:

// my_header1.h
#ifndef MY_HEADER1_H
#define MY_HEADER1_H

#include "my_header2.h"

int add(int x, int y);

#endif

// my_header2.h
#ifndef MY_HEADER2_H
#define MY_HEADER2_H

int subtract(int x, int y);

#endif

In this example, my_header1.h includes my_header2.h, which allows the subtract() function to be used in the implementation of the add() function.

Overall, header files are an essential tool for organizing and sharing declarations between source files in C++ programs. By using header files, you can create more modular and maintainable code.

# pragma once
...

this is a header guard that prevents us from including a header file multiple times in a single translation unit (.cpp file). not prevents us in multiple cpp.
you may ask why would i do that 😅 this is not only for one header file included twice this problem happens for nested includes which i personally cant handle all the time so including#pragma once is the best option.

include < > or include " ":
...

if its in the library directory like iostream use <> but if its in the relative path use " " like the header file you make while coding.

include<> or include<.h>
...

c++ library does not have .h but c libraries have .h at the end just to differentiate them.