WeCodeAcademy

C++ Variables and Types

Common types: int, double, char, bool, string. auto lets the compiler work out the type. const makes a constant.

ExampleC++
#include <iostream>
#include <string>
using namespace std;

int main() {
  string name = "Ada";
  int age = 36;
  double height = 1.68;
  bool student = false;
  char grade = 'A';
  const int YEAR = 2026;
  auto count = 10;   // int

  cout << name << " is " << age << endl;
  cout << height << " " << student << " " << grade << endl;
  cout << YEAR << " " << count << endl;
  cout << boolalpha << student << endl;
  return 0;
}
Output
Ada is 36
1.68 0 A
2026 10
false
Quick check

What does auto do?

Finish the quick check (and any code exercise) to complete this lesson, or mark it done yourself.

Tip: use the left and right arrow keys to move between lessons.