Hello World

Build the smallest complete v++ program and understand the program entry point, output, and exit status.

1

Core concepts

fn main() -> int, print, return, program entry point

2

How the learner should approach this project

Do not paste the complete program immediately. Create the file, type the first step, run vpp check, and then run the program when a complete entry point exists. Read the explanation before looking at the snippet. After each step, predict what the new code should do. This turns the page into a lesson rather than a code dump.

3

Step 1: Create the entry point

Every executable V++ program needs a place where execution begins. The function named main is that entry point.

Its return type is int because the operating system receives the integer status when the program finishes.

The braces define the body of main. Statements inside the body execute in order. The print call sends a string to standard output. The return statement finishes main and gives the operating system a success status.

Type the code yourself first. Then run it with vpp run.

After typing the snippet, identify the new names introduced by the step. Ask what each name represents, what type the compiler should infer or check, and what value should exist after the code runs.

main.vpp
fn main() -> int {
    print("Hello, v++!")
    return 0
}
4

Complete source

main.vpp
fn main() -> int {
    print("Hello, v++!")
    return 0
}
5

Expected behavior

The complete program should produce the following output when run with the command shown below. Exact formatting should follow the current V++ runtime.

Hello, v++!
6

Run the project

terminal
vpp run projects/01-hello-world/main.vpp
7

What the learner should understand after this project

Execution starts at main. A function signature is part of the language contract. Printing and returning are separate operations.

8

Common mistakes to teach

  1. Forgetting the main function
  2. Forgetting the return type
  3. Putting statements outside a function body
9

Practice extension

Change the message, then create a second print call. Keep the return statement at the end and explain why main returns an integer.

A strong learner should be able to explain the program without looking at the code, rebuild the core idea from memory, and make the practice change without copying a solution.

10

Full program

main.vpp
fn main() -> int {
    print("Hello, v++!")
    return 0
}
vpp
$ ready. Click Test program.