如果我想bi是一個long int
,是不可能使用自動,因爲它總是分配爲int?當我使用自動bi = 123456789,在C++中,它總是被分配爲一個int?
2
A
回答
11
一些選項:以上
auto bi = "123456789"; // const char*
auto bi2 = 12345; // int
auto bi3 = 123456789; // int (when int is 32 bits or more)
auto bi4a = 123456789L; // long
auto bi4b = 178923456789L; // long long! (L suffix asked for long, but got long long so that the number can fit)
auto bi5a = 123456789LL; // long long
auto bi5b = 123456784732899; // long long (on my system it is long long, but might be different on ILP64; there is would just be an int)
auto bi6 = 123456789UL; // unsigned long
auto bi7 = 123456789ULL; // unsigned long long
所有的例子取決於您所使用的系統上。
在標準中,在[lex.icon]
表5 - 整數常量的類型被引用:
類型字面的整數的是表5中的第一相應列表 ,其中它的值可以被代表。
如果我們看一下表十進制文本我們看到U
和L
後綴的甚至影響取決於可容納多大尺寸:
相關問題
- 1. C++:可以爲int分配一個char *?
- 2. C++我可以使用string :: at來分配一個int嗎?
- 3. NSLayoutConstraint並分配一個變量,它是一個int
- 4. 在C++中爲const int分配一個指針變量?
- 5. 爲什麼我不能按值分配$ this,它總是通過引用總是被賦值?
- 6. 在c#中,當一個int存儲在一個List <int>或int []中時,int仍然在堆棧上,還是被裝箱/移動到堆中?
- 7. 是否有一個智能指針,當它的目標在C++中被銷燬時自動爲空
- 8. 屬性或索引「string.this [INT]」不能被分配到 - 它只是
- 9. 在C++中什麼是分裂一個int爲位
- 10. 當我使用*(int *)&x分配一個常量值x時會發生什麼?
- 11. 爲什麼Xcode的自動完成總是認爲我的屬性是int?
- 12. C++:性病::地圖<int,int>崩潰時被分配
- 13. 當主鍵被認爲是一個自然鍵,並且當它被認爲是代理鍵?
- 14. 爲什麼一定要我投來(INT?)在C#中,當變量類型爲[INT?]
- 15. C++當我將一個字符串轉換爲一個int時,int只是一個隨機數?
- 16. 使用變量之前,它已被分配一個值
- 17. Rails中,如何設置一個外鍵被自動分配
- 18. 在一個結構內動態分配一個int數組
- 19. 爲什麼我們總是分配Objective-C原語?
- 20. 如何使用C中的方法將int分配給int *?
- 21. 接收「的表達被分配必須是常量」當它是
- 22. 當我使用String.split時,我總是收到一個「ArrayIndexOutOfBounds」異常
- 23. 當我使用g.FillEllipse()時,我總是收到一個Null異常。
- 24. 可以在C++中爲函數內的數組分配一個Int值?
- 25. 的Objective-C:一個NSMutableArray中的變化值,自動改變分配給它
- 26. 當我在C++中得到一個向量的索引時,它總是返回推回的最後一個值
- 27. 爲什麼它總是一個空值?
- 28. C++複製分配和移動分配不被稱爲
- 29. 爲什麼我的polymorphic_type字段不能被rails自動分配
- 30. Array.FindIndex總是在統一C中爲空#
爲什麼你認爲它「賦值爲int」? – juanchopanza
如果你用引號包裝它,它絕對不會是一個整數。這將是一個'char const *'(我認爲)。 ---你可以像上面提到的[這裏]檢查變量的類型(http://stackoverflow.com/questions/81870/is-it-possible-to-print-a-variables-type-in-standard-c ) – byxor
如果你特別想讓它成爲'long',那麼爲什麼不直接給編譯器'long bi ='說呢? –