Tsallaka zuwa abun ciki
Justice Tech School

Variables and Types

C++ is statically typed. Common types are int, double, char, bool and std::string. auto lets the compiler infer the type.

Example
#include <iostream>
#include <string>

int main() {
  int n = 5; double d = 2.5; char c = 'A'; bool ok = true;
  auto s = std::string("hi");
  std::cout << n << " " << d << " " << c << " " << ok << " " << s << "\n";
  return 0;
}

Result

5 2.5 A 1 hi

Exercise

Infer the type.

 x = 10;

Quiz Test

What does auto do?

These free lessons are for learning. Join a full course for projects, mentor feedback and a verified certificate.