Welcome to collectivesolver - Programming & Software Q&A with code examples. A website with trusted programming answers. All programs are tested and work.

Contact: aviboots(AT)netvision.net.il

Buy a domain name - Register cheap domain names from $0.99 - Namecheap

Scalable Hosting That Grows With You

Secure & Reliable Web Hosting, Free Domain, Free SSL, 1-Click WordPress Install, Expert 24/7 Support

Semrush - keyword research tool

Boost your online presence with premium web hosting and servers

Disclosure: My content contains affiliate links.

39,870 questions

51,793 answers

573 users

What is the type of auto in C++

1 Answer

0 votes
#include <iostream>

int main() {
    auto bl = true; // bool
    auto chr = 'z'; // char
    auto in = 123; // int
    auto dbl = 321.87; // a double
    auto str = "c++"; // string
    auto ptr1 = &in; // pointer to int
    auto ptr2 = &dbl; // pointer to double
    auto *ptr3 = &chr; // pointer to char
    auto *ptr4 = &in; // pointer to int
    
    std::cout << "bl: " << typeid(bl).name() << '\n'; 
    std::cout << "chr: " << typeid(chr).name() << '\n'; 
    std::cout << "in: " << typeid(in).name() << '\n'; 
    std::cout << "dbl: " << typeid(dbl).name() << '\n'; 
    std::cout << "str: " << typeid(str).name() << '\n'; 
    std::cout << "prt1: " << typeid(ptr1).name() << '\n'; 
    std::cout << "prt2: " << typeid(ptr2).name() << '\n'; 
    std::cout << "prt3: " << typeid(ptr3).name() << '\n'; 
    std::cout << "prt4: " << typeid(ptr4).name() << '\n'; 
}




/*
run:

bl: b
chr: c
in: i
dbl: d
str: PKc
prt1: Pi
prt2: Pd
prt3: Pc
prt4: Pi

*/

 



answered Feb 26, 2023 by avibootz

Related questions

...