Langage typé

Toute variable C++ doit avoir un type connu (à la compilation).
int main() {
    int a = 1;
    int b = a+6;

    float c = 5.1f;
    float d = 2.0f * c;

    std::string s = "A word";
    s = s + " and another word";

    std::cout<<a<<","<<b<<std::endl;
    std::cout<<c<<","<<d<<std::endl;
    std::cout<<s<<std::endl;

}
> 1,7
> 5.1,10.2
> A word and another word
Inférence automatique du type possible par le compilateur.
int main() {
    auto s = "My string";
    auto f = 3.14f;
}