Can I use the whole array? | Sololearn: Learn to code for FREE!
¡Nuevo curso! ¡Todo programador debería aprender IA Generativa!
Prueba una lección gratuita
0

Can I use the whole array?

Is it possible to use in code the whole array without specifying which of its members should it be but to use them all without using for loop?

9th May 2019, 8:09 AM
matuush
matuush - avatar
6 Respuestas
+ 2
Can you describe what exactly you want to achieve?
9th May 2019, 10:27 AM
HonFu
HonFu - avatar
+ 2
If it's a raw (C-style) array, you can pass the array, but it will be only a pointer, so you have to pass the size as well so that your function knows the limit. If it's the array template you're using, you can pass it as a reference and use it normally in the function.
9th May 2019, 11:13 AM
HonFu
HonFu - avatar
+ 1
as far you know the length of the array, you can write to it directly
9th May 2019, 8:23 AM
✳AsterisK✳
✳AsterisK✳ - avatar
0
But what if its written only by user?
9th May 2019, 8:36 AM
matuush
matuush - avatar
0
You mean without specifying the data type? Sure: use void*. But you'll loose typesafety at compile time.
9th May 2019, 11:09 AM
Daniel Adam
Daniel Adam - avatar
0
no. I mean it to use it as a function parameter or things like that.
9th May 2019, 11:10 AM
matuush
matuush - avatar