Ready to practice?
Sign up to access interactive coding exercises and track your progress.
Back to C++ Programming Fundamentals
Lesson 4 of 15
Beginner
45 minutes
Statements and the structure of a program
Learn how C++ programs are organized and understand the basic structure of statements.
Prerequisites
Understanding and Reading C++ Errors
Not completed
Statements and the Structure of a Program
What is a Statement?
A statement is an instruction that tells the computer to perform some action. In C++, statements are the building blocks of programs.
Types of Statements
Expression Statements
Most common type - expressions followed by a semicolon:
x = 5; // Assignment statement
cout << x; // Output statement
++x; // Increment statement
Declaration Statements
Create and name variables:
int x; // Declares variable x
int y = 10; // Declares and initializes y
Compound Statements (Blocks)
Group multiple statements with braces:
{
int x = 5;
cout << x;
x = x + 1;
}
Program Structure
Every C++ program follows this basic structure:
#include <iostream> // Preprocessor directive
int main() { // Main function
// Statements go here
return 0; // Return statement
}
Key Points
- Every statement must end with a semicolon (;)
- The main() function is where program execution begins
- Statements execute in order from top to bottom
- Use proper indentation for readability
Statements and the structure of a program - Quiz
Test your understanding of the lesson.
7 questions
10 minutes
60% to pass
Lesson Discussion
Share your thoughts and questions