In addition to Weibo, there is also WeChat
Please pay attention
WeChat public account
Shulou
2025-02-23 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Development >
Share
Shulou(Shulou.com)06/02 Report--
This article mainly introduces "what are C # arrays and pointers". In daily operation, I believe many people have doubts about what C # arrays and pointers are. The editor consulted all kinds of materials and sorted out simple and easy-to-use operation methods. I hope it will be helpful for you to answer the question of "what are C # arrays and pointers?" Next, please follow the editor to study!
C # array and pointer
one. The difference between a C # array and a vector is that the length of the C # array is fixed. Once the C # array is created, dynamic length modification is not allowed. Pointers can be used like iterators to traverse and retrieve elements in a C # array. Modern C++ programs should try to use vector and iterator types instead of using low-level C # arrays and pointers. Use C # arrays and pointers inside the class implementation only when speed is emphasized.
two. The drawback of the C # array is that there is no size () operation, that is, the programmer cannot know the length of a given C # array. If you need to change the length of the C # array, you must declare a larger C # array to copy the contents of the original C # array into the new C # array.
three. References cannot define a C # array. Not all elements are referenced C # arrays.
four. Neither the non-const variable nor the const variable that knows the value until run time can be used as the dimension of the C # array definition.
Const unsigned buf_size = 512; / / const variable. Int staff_size = 217; / / non-const variable. Const unsigned sz = get_size (); / / const variable determined at run time. Char Buf1 [Buff _ size]; / / ok. Char buf2 [buff _ size + 1]; / / ok, constant evaluation expression. Double const [staff _ size]; / / error, non-staff variables are used as dimensions. Int test_ [sz]; / / error, the const variable determined by the runtime.
five. Default initialization.
The elements of the built-in type C # array defined outside the function are initialized to 0. The built-in type C # array defined in the function has no initialization process for the elements. In the case of a C # array of class types, the default constructor initialization is called no matter where it is defined.
six. Show initialization.
Int ia [3] = {0,1,3}; char ca1 [] = {'clocked,' +','+'}; char ca2 [] = {'clocked,' +','+','\\ 0'}; [Page] char ca3 [] =\ "C++\"; / / ca3 and ca2 have the same dimension and initialization value and contain four elements. Char ca4 [3] =\ "C++\" / / this produces a compilation error because\ "C++\" is a string of length 4. String str_arr [3] = {\ "hi\",\ "heipi\"}; / / str_arr [2] is an string type element with an empty value.
seven. Unlike vector, a C # array cannot be initialized with another C # array, nor can a C # array be assigned to another C # array. Individual compilers extend functionality to support C # array replication, but such applications should be avoided if you want to write programs that can run on different compilers.
At this point, the study of "what are the C # arrays and pointers" is over. I hope to be able to solve your doubts. The collocation of theory and practice can better help you learn, go and try it! If you want to continue to learn more related knowledge, please continue to follow the website, the editor will continue to work hard to bring you more practical articles!
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.
Continue with the installation of the previous hadoop.First, install zookooper1. Decompress zookoope
"Every 5-10 years, there's a rare product, a really special, very unusual product that's the most un
© 2024 shulou.com SLNews company. All rights reserved.