Auto type Use

Source: Internet
Author: User

It is not uncommon to want to store the value of an expression in a variable. To
Declare the variable, we have to know the type of the. When we write a
program, it can be surprisingly difficult-and sometimes even impossible-to
Determine the type of an expression. Under the new standard, we can let the compiler
The type for us by using the auto type specifier. Unlike type specifiers, such
As double, that's name a specific type, auto tells the compiler to deduce the type
From the initializer.

Auto Item=val1+val2;

The following statement is incorrect:

Auto a=0,b=3.14;//variable A is inconsistent with type B

Auto requires consistent variable types defined within the same row

Auto usually ignores the top-level const without ignoring the underlying const, such as:

Const int ci=i,&cr=ci;auto b=ci; // The top-level const is ignored by auto C=CR; // CR is the alias of the top-level CONSTCI Auto e=&ci; // e is a pointer to a const object, and E is the underlying const

If you want the auto type to have a top-level const property, you need to declare it:

const Auto b=ci; // at this point B has the top-level const property

Auto type Use

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.