Hello. I was wondering how to swap array in place of another array. For example, if my array is 1, 4 , 9, 10, 15. I want to produce 15, 10, 9, 4 , 1. This is my attempt on it:
Yeah I just realised that now, list[7] would only replace the last character or, in this case undefined. But, I have no idea of how to fix it. I've tried list[counter] while passing by reference of counter. Still didn't work.
Prefer using STL array or vector instead of a C array
Reason
C arrays are less safe, and have no advantages over array and vector. For a fixed-length array, use std::array, which does not degenerate to a pointer when passed to a function and does know its size. For a variable-length array, use std::vector, which additionally can change its size and handles memory allocation.
Oh, thanks guys, I figured it out. But, I lack the understanding of "temp" function. I mean is it really a function that is imprinted in the C++ programs. And what does it do?
"C arrays are less safe, and have no advantages over array and vector."
disagree %100 - if you know the size of data you will store arrays are much faster
"Vectors are much Higher level constructs, internally they have many moving parts compared to a simple array " -Quara
and unsafe? - the entirety of C is based off pointers to arrays - so you just called C - which runs your C++ compilers unsafe
just because C/C++ doesn't have bounds checking doesn't mean it is unsafe it actually lets you do a lot more and is like that for a reason
if you know the size of data you will store arrays are much faster
Are you saying that C arrays will be faster than std::arrays? How is that possible?
and unsafe? - the entirety of C is based off pointers to arrays - so you just called C - which runs your C++ compilers unsafe
C is unsafe. It's weakly typed, so the compiler will let you call a flood fill function on a bignum without any warnings; it provides practically no mechanisms to enforce invariants at compile time; it provides no form of automatic resource management for any non-trivial type.
just because C/C++ doesn't have bounds checking doesn't mean it is unsafe it actually lets you do a lot more and is like that for a reason
C is the way it is as a direct consequence of the time when it was designed. Not everything in it is the way it is because that was the best way to do it. Some things are like that because of historical reasons, and some things are because there was just no other way to make compilers that could terminate in a reasonable time. Could you imagine compiling even a simple Boost.Spirit program on a PDP-11?