C++ Basic Syntax
Essential C++ syntax and program structure
Program Structure
#include <iostream> # include library
using namespace std; # use std namespace
int main() { # main function
cout << "Hello World!"; # output to console
return 0; # exit program
}
Variables
int age = 25; # integer variable
double price = 99.99; # floating point
char grade = 'A'; # single character
bool isTrue = true; # boolean value
string name = "John"; # text string
Input and Output
cout << "Text" << endl; # print with newline
cin >> variable; # read input
cout << a << " " << b; # multiple values
Comments
// single line comment
/* multi-line
comment */