What is the value of arysize after executing the following code: Answer: int testAry[] = { 1,5,8,9,6,7,3,4,2,0 }; int arysize = sizeof(testAry) / sizeof(testAry[5]); 0101 111101101 01010 To pass an object of type struct or class to a function as an argument, which of the following is true? (Select all that apply) a. You can pass it by reference b. You can pass it by value c. You can pass it by value but not by reference d. You can pass it by reference but not by value e. None of the answers Based on the code of contiguous queue, create a non-member function (friend) that uses operator overloading to overload the '+' operator. The function will add each element of the first queue with the corresponding element from the other queue.
output : 1
this is because sizeof(arysize) represent the size of first element and it is divided by element at 5th index , where size of every element in array is same so when they divide gives 1;
object pass to function:
C++ always gives you the choice: All types T
(except arrays, see below) can be passed by value by making the parameter type T
, and passed by reference by making the parameter type T &
, reference-to-T
.
When the parameter type is not explicitly annotated to be a reference (type &myVariable
), it is always passed by value regardless of the specific type. For user-defined types too (that's what the copy constructor is for). Also for pointers, even though copying a pointer does not copy what's pointed at.
Arrays are a bit more complicated. Arrays cannot be passed by value, parameter types like int arr[]
are really just different syntax for int *arr
. It's not the act of passing to a function which produces a pointer from an array, virtually every possible operation (excluding only a few ones like sizeof
) does that. One can pass a reference-to-an-array, but this explicitly annotated as reference: int (&myArray)[100]
.
Step by step
Solved in 2 steps