How to run your first C and C++ program in Code::Blocks

This guide walks you through opening Code::Blocks, writing a small C or C++ program, and building and running it on Windows 10 or 11. It suits students and first-time programmers. You need Code::Blocks installed with the MinGW GCC compiler.

YouTube video: CodeBlocks for Beginners | Running C/C++ Programs in CodeBlocks 2026

YouTube’s video details do not confirm captions. Check CC in the player for available tracks.

Video length
9 min 26 s
Time to do it
10 minutes
Difficulty
Easy
Steps
6

What you need

Steps

  1. Open Code::Blocks from the Start menu. If a compiler dialog appears, pick the GNU GCC Compiler entry and click OK.

  2. Click File, then New, then Empty file. Save it as hello.c for C or hello.cpp for C++.

  3. Type a short program. For C, include stdio.h and print text with printf. For C++, include iostream and use std::cout.

  4. Press F9 or click the Build and run icon (a gear with a green arrow) on the toolbar.

  5. Read the Build messages tab at the bottom. Fix any red error lines, then build again.

  6. Check the console window that opens. It shows your program output, such as Hello World.

Tips and common mistakes

Save the file with the right extension,.c for C and.cpp for C++, or the compiler may treat it as the wrong language.

If the build fails, open Settings, then Compiler, and confirm GNU GCC Compiler is selected as the default.

Close the console window with any key press when the program asks, so the run finishes cleanly.

Questions

Do I need to install a compiler separately?

No, if you download the codeblocks-20.03mingw-setup installer, the MinGW GCC compiler comes bundled. Choose that version on the download page.

Why does my program close instantly?

The console may flash and close when the program ends. Add a line like getchar() in C or std::cin.get() in C++ before the closing brace to pause it.

Can I use the same steps for C++?

Yes. The build and run buttons work the same way. Just save the file as.cpp and use C++ headers and syntax.

The notes are drafted automatically from video details and general task knowledge. How the guide was prepared

Report a correction

More in Computers & Phones

See all