Network Security Internet Technology Development Database Servers Mobile Phone Android Software Apple Software Computer Software News IT Information

In addition to Weibo, there is also WeChat

Please pay attention

WeChat public account

Shulou

Talking deeply about auto variable

2025-02-24 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Network Security >

Share

Shulou(Shulou.com)06/01 Report--

1. There is a keyword in auto,c +, but the meaning of the two is quite different.

2. The variable defined by auto in C codes + automatically matches the type of the value on the right of the assignment symbol, with the function of automatically matching type, while auto in c language only declares a variable as an automatic type, indicating that the code block lifetime of this variable and allocation on the stack, and can not be used to define variables.

3. Auto can play the role of generics in clocked +. No matter what type you pass to me, I can recognize it and use this variable by type.

4. Let's look at the cpp test code.

1 # include 2 3 using namespace std; 4 5 / * 6 automatic variable: automatic matching type 7 auto num = pc; generic incoming interface 8 decltype (num) anum;/ generic backup interface 9 * / 10 11 void main () 12 {13 14 auto a = 10 auto auto / parsing a to integer variable 15 auto b = 10.1 auto / parsing b to floating point variable 16 17 int array [10]; 18 int I = 0 19 for (auto arr: array) / / enhanced for cycle 20 {21 arr = iDeposition22 cout

Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.

Views: 0

*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.

Share To

Network Security

Wechat

© 2024 shulou.com SLNews company. All rights reserved.

12
Report