0
why do we define the header files in many programming languages ?
why do we use header files ?
3 ответов
+ 2
Check here what is header and why we use.
https://www.tutorialspoint.com/cprogramming/c_header_files.htm
https://www.sololearn.com/discuss/158592/?ref=app
https://www.sololearn.com/discuss/2147846/?ref=app
https://www.sololearn.com/discuss/112829/?ref=app
https://www.sololearn.com/discuss/586662/?ref=app
0
Hey Mitraj Gohil do use the search bar before asking question
0
Mitraj Gohil I think that what he is asking for is why is the:
#ifndef MYCLASS_H
#define MYCLASS_H
...
#endif
if that's the case the reason why we do that is so that your code is not being repeated in case of multiple includes e.x:
consider a .h file: file0.h
In file1.h:
#include"file0.h"
...
In file2.h:
#include"file0.h"
#include"file1.h"
...
You see that what happens here is that the contents of file0.h are being copyied twice to file2.h. That's bad cause there might be errors of redefinition, redeclaration. By defining FILE0_H the contents of file0 are only being copyed the first time since the second time, #ifndef FILE0_H prevents it. Another way to do the same thing is by typing #pragma once on top of the header file