Hello World
Build the smallest complete v++ program and understand the program entry point, output, and exit status.
Core concepts
fn main() -> int, print, return, program entry point
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.
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.
fn main() -> int {
print("Hello, v++!")
return 0
}Complete source
fn main() -> int {
print("Hello, v++!")
return 0
}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++!
Run the project
vpp run projects/01-hello-world/main.vppWhat 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.
Common mistakes to teach
- Forgetting the main function
- Forgetting the return type
- Putting statements outside a function body
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.
Full program
fn main() -> int {
print("Hello, v++!")
return 0
}