Many times while coding we always want to test how a small snippet of our code would actually perform or we would just want to check or confirm a logic of our program. In this blog I will show you how you can write a C++ code snippet in to check your code logic in just two minutes without writing a CmakeLists.txt.

You will first need to download vscode as the instructions are using this editor. You can download it from this link  Then lets create a test folder in /tmp directory and add a test.cpp in it. Open a Terminal and type:
mkdir -p /tmp/test_code && cd /tmp/test_code
touch test.cpp
code .
Now you can write you own code snippet or copy it from the example I provide below. In this code I want to test return of a pointer through a function.
#include <stdio.h>
#include <math.h>
#include <iostream>

int *set_foo_pointer(int a, int b)
    int *c = new int;
    *c = pow(a, 2) + pow(b, 2);
    std::cout << "Value of c: " << *c << std::endl;
    return c;

int main()
    int *a = new int;
    a = set_foo_pointer(3, 5);
    std::cout << "Value of a: " << *a << std::endl;
    return 0;
After writing the code you can execute the following two steps on the same terminal you opened the vscode.
g++ test.cpp 
The first line compiles the code using g++ and the second line executes the compiled output. Which after running should print the following output:
Value of c: 34
Value of a: 34