Tutorial: How To Execute Code Examples

While you are a beginner, most of your code will be in the form of short snippets and examples. This tutorial shows you how to compile and run (execute) these examples. It's also useful to execute code for small programming experiments that don't require creating a new project in Code::Blocks.

1. Go to File -> New -> Blank File (or hit Ctrl+Shift+N)

This will open up the code editor completely blank.

2. Type in or copy and paste your code in the code editor.

You can use this code :

#include <iostream>
using namespace std;
 
int main()
{
    //This prints "Hello World!" on the screen
    cout << "Hello World!" << endl;
    return 0;
}

3. Go to File -> Save.

4. Go to Build -> Build and Run.

This will compile the code and run it.

While working on code, it's important to save it before building and running it. If you don't, the compiled .exe won't show the changes to your code.

Also, if there are errors in your code they will be reported when you try to compile. This helps you correct any mistakes.

Next Steps

Categories: Beginner Tutorials : Code-Blocks Tutorials : Source Code : Tutorials
page_revision: 10, last_edited: 1245772236|%e %b %Y, %H:%M %Z (%O ago)