0
I dont know why the function doesnt recognize the whole array
i have a problem with a function to receive an array from the main(); where it doesnt recognize the whole array size in bytes inside the Print function , but it does inside the main(); function. I leave to you the code so you can see what its the problem because i dont see it, please help https://code.sololearn.com/cL2K11C7Q7Yh/?ref=app
7 Antworten
+ 4
you can do that by passing a reference to an array ( only in c++ ):
https://code.sololearn.com/c3ladI1DwtRx/#cpp
the syntax int(&arr)[N] means "reference to an array of N int." this explicitly passes the array by reference into printArray, and it will capture the size of the array at compile time. however, this is very unusual syntax and rarely seen in practice.
perhaps the best idea is to not use raw arrays but you should use the STL container std::array or std::vector as HonFu mentioned.
+ 3
C-style arrays don't get passed full value, but only the pointer is passed (which is 8 bytes).
+ 2
Mohamed ELomari thanks for the explanation and the code really helped dude
+ 2
Drew, you don't have to study the whole object oriented area of C++; these are just tools from the standard library that you can use.
Normally you'll find a section somewhere in a tutorial 'container classes or something'. Let me see if I find anything... ah yeah, here!
https://medium.com/the-renaissance-developer/c-standard-template-library-stl-vector-a-pretty-simple-guide-d2b64184d50b
+ 1
HonFu thanks, and how do i solve it? which array allows me to pass full value?
+ 1
If you work with C arrays, you usually pass the size as a second argument.
If you don't want that (writing C++ you mostly don't), you can use the classes vector or array; they come with their own length properties and methods to manipulate the content.
(You should still not pass the whole thing as value, but as reference or pointer.)
+ 1
HonFu thanks for the info man, i havent got too much into classes properties yet, got to learn more about it