1consider this code segment
int nums[10];
nums[10] = 999;
which of the following is true?
the code will compile but there is something wrong with this code
there is nothing wrong with the code
the code will not compile
C++ is a dnerous motorcycle and you could be mortally wounded if you try to use it
the code will compile but there is something wrong with this code
2the fibonacci function is a recursive function. each time the function gets called in a recursive loop, what type of memory is used to store the contents and state of the program?
heap
stack
register
ram
stack
3suppose I have a file numbers.dat with the number 1 through 1000 sorted, one number per line. What will be printed on the screen if I type this command sequence:
% more numbers.dat |tail -100 | head -20 | tail -1
901
920
921
none of these
920
4consider the following code:
int a = 10;
int *ptr = &a;
cout << ptr;
what is printed?
the memory address of ptr
the number 10
the contents of a
the memory address of a
the memory address of a
5consider this code segment:
int x = 10;
int y = 20;
int z = mystery(x,y);
cout << z << "/" << x + y;
also consider this function:
int mystery (int a, int b){
a += 5;
b += 5;
return a + b; }
what is printed?
40/35
40/30
30/40
35/40
40/30
6when using linux comands, how would I find out more about the wc command?
man wc
help wc
list wc
more wc
man wc
7suppose I have a vector that I want to pass to a sort() function.
vector<int> v;
//vector gets filled
sort (v);
//sorted
what does the signature of the sort function look like?
void sort(vector<int> * vec)
void sort(vector<int> & vec)
void sort(vector<int> vec)
the correct answer isn't shown
void sort(vector<int> vec)
8when a C++ program runs and dynamic memory is needed, where does the allocated dynamic memory live in memory
register
stack
ram
heap
heap
9consider the following segment of code in C++:
int nums[10] = {1,2,3,4,5,6,7,8,9,10};
printArray(nums);
consider this function
void printArray(int n[]){
for (int i = 0, i < n.size; i++){
cout << n[i];
}
}
How many numbers does the function actually print?
10
all the numbers in the array
1
The correct answer isn't here
The correct answer isn't here (errors)
10consider the following code segment in C++
int A[] - {0,1,2,3,4,5};
int *ptr = A;
how would I print 5 to the screen?
cout << ptr[5];
cout << ptr * 5
cout << ptr + 5
cout << *ptr[5];
cout << ptr[5];