What will be the value of vec[2], the third element in the vector, after this code executes?
int main()
{
const int LENGTH = 4;
int vec [LENGTH];
vec[0] = 3;
vec[2] = vec[0];
vec[0]++;
return 0;
}
0
1
3
4
3
So, we can see that vec[0] is set to 3 and then vec[2] is set to vec[0]. Since vec[0] has 3 stored, vec[2] becomes 3. Now vec[0] and vec[2] are not pointers, so the copy is a deep copy, i.e only the value is copied and any change to vec[0] will not reflect on vec[2]. vec[0]++ changes vec[0] to 4, but vec[2] remains 3.
What will be the value of vec[2], the third element in the vector, after this code...
2 Class Vec Message1 2.1 Introduction • Write a class Vec Message1 with the following declaration. class Vec_Message1 { public: Vec_Message1(); Vec_Message1(int n); Vec_Message1(int n, const Message1 &a); Vec_Message1(const Vec_Message1 &orig); Vec_Message1& operator= (const Vec_Message1 &rhs); ~Vec_Message1(); int capacity() const; int size() const; Message1 front() const; Message1 back() const; void clear(); void pop_back(); void push_back(const Message1 &a); Message1& at(int n); private: void allocate(); void release(); int _capacity; int _size; Message1 * _vec; }; 2.2 allocate() and release() • Examine the...
What is the value of result after the following code executes? int a = 60; int b = 15; int result = 20; if (a = b) result *= 3; 30 20 60 10 code will not execute The numeric data types in C++ can be broken into two general categories which are integers and floating-point numbers singles and doubles real and unreal numbers numbers and characters numbers and literals Which line in the following program will cause a compiler error?...
What will be the value of w after the following section of code executes: int w = 4, 9 = 3; if (a < 5) if (w == 7) W = 3; else W = 3; else if (w > 3) W = 2; else W = 1; Select one 2.3 0 b.o 0.2 d. 1
Implementing the function method using c, some sample codes are showed below: typedef struct{ double *vector; int count; int length; }Vector; Vector create_vector(int length){ Vector vec; vec.vector = (int*)malloc(sizeof(int)*length); if (vec.vector == NULL){ vec.length = 0; vec.count =0; return vec; }vec.count =0; vec.length = length; } /* Calculate and return the variance of the elements in a vector. */ double var(Vector vec) { } /* Calculate and return the standard deviation of the elements in a vector. */ double stdv(Vector...
1- Complete all the blanks in the function f1() below such that it implements the operations described in the comments. You may only fill in the blanks and not add or alter other code. Also complete main(). // f1 copies the last *half* of vec's values into a new array pointed to 'arr'. // 'arr' is garbage coming in and must be modified by this function so the // caller can then use the produced array. The values copied from...
C++ int num [ ] = { 1,2,3,3,4,5,6,7,8 } vector <int> vec (num, num + 8) ; vector <int> : : iterator iter ; iter = vec . begin ( ) ; Question 1. What is the result of execute the instruction num [4] ;? a)2 b)7 c) unknown Question 2. How many elements does the vector vec contain? a)0 b)10 c)16
For any element in keysList with a value greater than 50. print the corresponding value in itemsList, followed by a comma (no spaces) Ex: If the input is 32 105 101 35 10 20 30 40 the output is 20,30, 1 include <stdio.h> 2 3 int main(void) { 4 const int SIZE LIST - 4 5 int keysList[SIZE LISTI: 6 int itemslist[SIZE_LIST); 7 int 1; 8 9 scanf("%d", &keysList[0]); 10 scanf("%d", &keyslist[1]); 11 scanf("%d", &keysList[2]); 12 scanf("%d", &keysList[]); 13 14...
C++ program Write a code segment to find the max element in each row and then store the values to the "result" array. For example, { {2, 7, 9, 6, 4}, => 9 {6, 1, 8, 10, 4}, => 10 {4, 3, 7, 2, 9}, => 9 {9, 9, 0, 3, 1}, => 9 {8, 8, 7, 8, 9}, => 9 {1, 2, 1, 2, 3} } => 3 the result array has the values [9, 10, 9, 9, 9,...
In the blank below, write the contents of array arr after the following code is executed up to the comment indicated in the main procedure below? #include <iostream> #include <algorithm> using namespace std; void do something(int list[], const int size); int main() { const int SIZE(10); int arr[SIZE] = { 5, 8, 1, 7, 3, 9, 4, 6, 10, 2 }; do somethingCarr, SIZE); ** Write the contents of array arr in the space below when execution reaches here. */...
What is the final value of x in memory after the code below is run? 1 int x; 2 for (x=0; x<5; x++){ 3 4} Answer: Answer What is the result of the following bitwise operation in decimal? ((~6)&36)|(6)&(~36)), where ~, |, and & are the bitwise NOT, OR, and AND respectively. Answer: Answer Complete the attempt to allocate a 5-element array of pointers to doubles and initialise the associated double value to 0.0. double* a[10]; for (int j =...