Question

C++ int num [ ] = { 1,2,3,3,4,5,6,7,8 } vector <int> vec (num, num + 8)...

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
0 0
Add a comment Improve this question Transcribed image text
Answer #1

Q1. A) Option : C

After executing the instruction num[4], nothing will happen. If you print the value by cout << num[4];. then 4 will be printed

Q2. A) No option is correct. Actually vector vec, contains 8 elements totally. Check the attached code

Hope this will clarify your doubts.Let me know, still if you have any queries..

Add a comment
Know the answer?
Add Answer to:
C++ int num [ ] = { 1,2,3,3,4,5,6,7,8 } vector <int> vec (num, num + 8)...
Your Answer:

Post as a guest

Your Name:

What's your source?

Earn Coins

Coins can be redeemed for fabulous gifts.

Not the answer you're looking for? Ask your own homework help question. Our experts will answer your question WITHIN MINUTES for Free.
Similar Homework Help Questions
  • Example program #include <string> #include <iostream> #include <cmath> #include <vector> using namespace std; vector<int> factor(int n)...

    Example program #include <string> #include <iostream> #include <cmath> #include <vector> using namespace std; vector<int> factor(int n) {     vector <int> v1;     // Print the number of 2s that divide n     while (n%2 == 0)     {         printf("%d ", 2);         n = n/2;         v1.push_back(2);     }     // n must be odd at this point. So we can skip     // one element (Note i = i +2)     for (int i = 3; i <=...

  • when will the (return) word take us? it will end the if or the while or both? 7 | 8 6 void insert(int num, int loc){...

    when will the (return) word take us? it will end the if or the while or both? 7 | 8 6 void insert(int num, int loc){ int par; while(loc>0){ 91 par=(loc-1)/2; if (num<=arr[par]) { arr[loc]=num; return; Oo own v L arr[loc]=arr par]; locupar; 16 F }/*End of while*/ arr[@]=num; /*assign num to t 18 - }/*End of insert() */ * *

  • What is the value of  result after the following code executes?   int a = 60; int b...

    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?...

  • question about c++ find function int num_to_id(int num) { static const int table[] = { 10,...

    question about c++ find function int num_to_id(int num) { static const int table[] = { 10, 15, 30, 50 }: assert(std::find(&table[0], &table[4], num) != &table[4]); return std::find(&table[0], &table[4], num) - &table[0]: } why do you need &table[0] and [4] and have to extract &table[0] from them ??

  • QUESTION 18 Rewrite this if/else if code segment into a switch statement int num = 0;...

    QUESTION 18 Rewrite this if/else if code segment into a switch statement int num = 0; int a = 10, b = 20, c = 20, d = 30, x = 40; if (num > 101 && num <= 105) { a += 1; } else if (num == 208) { b += 1; X = 8; } else if (num > 208 && num <210) { c=c* 3; } else { d+= 1004;

  • int num; int total = 0; cout << "Enter a number from 1 to 10."; cin...

    int num; int total = 0; cout << "Enter a number from 1 to 10."; cin >> num; switch (num) {    case 1:    case 2:   total = 5;    case 3:   total = 10;    case 4:   total = total + 3;    case 8:   total = total + 6;    default: total = total + 4; } cout << total; A. 10 B. 0 C. 23 D. 3 E. None of these

  • 3) [16 points total] Consider the following algorithm int SillyCalc (int n) int i; int Num, answer; if (n <=...

    3) [16 points total] Consider the following algorithm int SillyCalc (int n) int i; int Num, answer; if (n <= 4) return n 10; else { Num-SillyCalcl n/4) answer = Num + Num + 10; for (i-2; i<-n-1; ++) answer- answer+ answer; return answer; Do a worst case analysis of this algorithm, counting additions only (but not loop counter additions) as the basic operation counted, and assuming that n is a power of 2, i.e. that n- 2* for some...

  • 5.35 LAB: Sort a vector Write a program that gets a list of integers from input,...

    5.35 LAB: Sort a vector Write a program that gets a list of integers from input, and outputs the integers in ascending order (lowest to highest). The first integer indicates how many numbers are in the list. Assume that the list will always contain less than 20 integers. Ex: If the input is: 5 10 4 39 12 2 the output is: 2 4 10 12 39 For coding simplicity, follow every output value by a space, including the last...

  • C++ Question 12. Based on our Vector class which only held integers, we want to implement...

    C++ Question 12. Based on our Vector class which only held integers, we want to implement a class Iterator, sufficient to handle a ranged for. (You are not writing any part of the class Vector!!!) Our goal is for the following function to work properly, i.e. to double every int in the Vector v. void double(Vector& v) { for (int& val : v) { val *= 2; } } As you know, the Vector class must support the methods begin()...

  • 4.9 [10/20/20/15/15] Consider the following code, which multiplies two vec- tors that contain sin...

    4.9 [10/20/20/15/15]<4.2> Consider the following code, which multiplies two vec- tors that contain single-precision complex values: for (i-0:i <300:i++) Assume that the processor runs at 700 MHz and has a maximum vector length of 64. The load/store unit has a start-up overhead of 15 cycles; the multiply unit, 8 cycles; and the add/subtract unit, 5 cycles. a. [101 <4.3> What is the arithmetic intensity of this kemel? Justify your answer. b. [20] <4.2> Convert this loop into RV64V assembly code...

ADVERTISEMENT
Free Homework Help App
Download From Google Play
Scan Your Homework
to Get Instant Free Answers
Need Online Homework Help?
Ask a Question
Get Answers For Free
Most questions answered within 3 hours.
ADVERTISEMENT
ADVERTISEMENT