What are header files in C++ ( PROGRAMMING TUTORIAL for beginners)

C++ header files are files that usually have .h extensions and they contain declarations of variables, functions… The implementation of those functions goes into the implementation file.
By doing this, if the implementation does not change, there is no need to recompile the implementation file, which would not be possible if everything was in one file.

This also gives us the option to reuse the functions that are declared in the header file in multiple .cpp files. In order to do that you just need to include the corresponding header file in the .cpp file that wants to use those functions.

In this C++ programming tutorial, you will learn what are header files, how to create your own header file, and how to include it and work with it.

00:00 – Intro
02:48 – Before you learn header files, first understand this!
07:33 – What are header files used for?
08:27 – How program compilation works?
13:26 – How to create a header file and implementation file in Visual Studio 2019?
16:55 – What is include iostream?
21:47 – What is pragma once in header files

🎁🎁🎁 Get one month free trial of the PVS-Studio with #code_beauty promo code on the link below:

For more interesting info about analyzer and programming check out:
PVS-Studio Facebook group: https://www.facebook.com/StaticCodeAnalyzer/
PVS-Studio YouTube channel: https://bit.ly/2PFcrVu

Learn how to install and use PVS-Studio in this video: https://youtu.be/AeyTSLGIX1M
C++ functions Playlist: https://bit.ly/2PkYpII

Tag me on you Instagram stories:
Instagram 📸 – https://www.instagram.com/truecodebeauty/
Twitter 🐦- https://twitter.com/TrueCodeBeauty

37 thoughts on “What are header files in C++ ( PROGRAMMING TUTORIAL for beginners)

  1. Hi, I was wondering if you could do a video on breaking down large chunks of code in to smaller files using headers. I am often handed other peoples code and find it difficult to work on just a small part without destroying the whole program 🙃

  2. Thank you, it's much clearer now! 🤗 However, for some reason I encounter a problem 😥 VSCode returns an error: undefined reference to {the name of my function}
    However, it works fine if my main file (main.cpp) includes the implementation file (Food.cpp in your example) instead of the header file (Food.h), but I don't know why!
    Do you have any idea? 🤔

    EDIT: I found the source of the problem. It comes from my "Code Runner" extension for VSCode, which is unable to compile multiple files as is. For those interested, just run Code Runner but change g++ YOUR_MAIN_FILE.cpp to g++ *.cpp so that it compiles both your main file and your implementation file as well .

  3. Greetings from Maldives. Been watching this channel since last year. Like the way you present.
    I follow as a means of refreshing p-languages. Any plans in future videos you might cover
    header files like graphics.h or windows.h !! ,Really appreciate what you are doing for the viewers.
    Thank you.

  4. Can I make blogs/articles of your videos? I can't see any existing ones.
    Your content is great, easy to understand, and includes fundamental topics.
    I like to refer to written articles sometimes along with the video. I think many people do.
    Let me know what you think about it.

  5. Wow, I didn't know this channel, I'm going to have to watch all the videos haha, the teaching is very good for those who are just starting out and we still practice our English!
    I intend to go deeper into C ++, do you recommend first deeping into pure C first and then going to C ++? Or just see the C base and go to C ++ already?
    Besides, great video! : D

  6. Hi dear Saldina, why not using ifndef, define macros instead of pragma once? is it because it is more C style or?
    And also can you please post a video about C and C++ style differences, DOs and DON'Ts about it, also about cmake, this is really needed, no good resources on these topics, or if you know some resources that can help please share, thank you.

Leave a Reply

Your email address will not be published. Required fields are marked *