Need a couple quick questions answered please

1.)I'm trying to write code to swap element [2] and element [4] in an array of floats called ARR. I need to declare a simple variable called temp for this question, and assume the array is correctly declared and initialized.

2.)Also how would I write code to copy the 0th element of an array called ARR into all the other elements of the array assuming there are 10 elements in the array.
Sounds easy to me. You even explained how to accomplish #1 so you already know how to do it. However, you can let the STL do the work for you. Take a look at the swap, fill, and fill_n algorithms.
http://www.cplusplus.com/reference/algorithm/
I actually have no idea what I'm doing. This is all really new to me. How exactly would you write the code?
http://libraryofcprograms.blogspot.com/2012/12/function-swap-to-exchange-two-values-by-passing-arguments-by-reference-to-the-function.html

Little modification might be helpful for you. Above link takes you to a program in which values from two variables are swaped. Use array indexes instead of variables and you are done.
Topic archived. No new replies allowed.