Urgent simple question

In a program, there are these headers:

#ifndef Personh
#define Personh

and then at the bottom of the program is:

#endif;



What is the point of this? I haven't learned this yet, is there another way to accomplish its function?
Last edited on
I imagine the file there would be person.h.

If you included the contents of person.h twice, there would be an error, because you'd be defining whatever is in person.h twice which would create an error. (another example of that, int a = 4 then another int a = 6 would make an error, because you declare something already declared twice instead of changing)

So, when person.h is included, it'll define Personh. It doesn't give it a value but it'll be defined now. The only way for most of person.h to get defined is if Personh wasn't defined before (because most the content is between the ifndef and endif so that stuff is only included if the ifndef is true). So after person.h was included once, it cannot be included again. That way putting #include "person.h" twice wouldn't cause an error if done accidentally or whatever.

Essentially it just prevents it from being included twice so that there is no errors.

Also I notice that you have a ; on the last #endif. I don't think that is needed and would actually cause an error wouldn't it?
Last edited on
Topic archived. No new replies allowed.