Explain what each line of the following snippet of code does:
int *ptr;
ptr = new int;
*ptr = 10;
cout << ptr << ' ' << &ptr << ' '
<< *ptr;
delete ptr;
cout << ptr << ' ' << &ptr << '
' << *ptr;
//declaring a pointer int *ptr; //assigning memory for the pointer variable ptr = new int; //Assigning value to the memory address sored in the ptr variable *ptr = 10; //printing the value of ptr //then printing the address of ptr //then printing the value of address stored in ptr cout << ptr << ' ' << &ptr << ' ' << *ptr; //delete ptr delete ptr; //printing the value of ptr //then printing the address of ptr //then printing the value of address stored in ptr cout << ptr << ' ' << &ptr << ' ' << *ptr;
Explain what each line of the following snippet of code does: int *ptr; ptr = new...
Consider the following code snippet. What will be printed by *ptr and ptr after the lines shown. Explain with screenshots. int a[4] = { 8, 3, 5, 6}; int *ptr = a; ptr ++;
51. What is the output of the following code snippet? int number = 0; int ptr_num -&number ptr_num 60; number-80 cout < "ptr num << endl b, 60 c. 80 d. the address of number Answer 52. What is the output of the following code snippet? double num-0.0; double* ptr = # num = 15.0; ptr ptr 15.0 cout << num <<"ptr <<endl; a. 15 15 b. 15 30 ะก. 30 15 d. 30 30 Answer: 53. What is the...
c++ only. Please follow directions. What does the following program print and why? Comment each line of code to explain what it is doing. #include <iostream> using namespace std; int main() { int track[ ] = { 10, 20, 30, 40 }; int * ptr; ptr = track; track[1] += 30; cout << * ptr << " "; *ptr -= 10; ptr++; cout << * ptr << " "; ptr += 2; cout << * ptr << " "; cout...
What is wrong with the following code snippet? int main() { int width = 10; height = 20.00; cout << "width = " << width << " height = " << height << endl; return 0; } The code snippet uses an uninitialized variable. The code snippet uses an undefined variable. The code snippet attempts to assign a decimal value to an integer variable. The code snippet attempts to assign an integer value to a decimal variable.
QUESTION 1 What is the output of the following code snippet? int main() { bool attendance = false; string str = "Unknown"; attendance = !(attendance); if (!attendance) { str = "False"; } if (attendance) { attendance = false; } if (attendance) { str = "True"; } else { str = "Maybe"; } cout << str << endl; return 0; } False True Unknown Maybe QUESTION 2 What is the output of the following code snippet? #include <iostream> #include <string> using...
What is the value of n after the following snippet? int n = 13, m = 16; int* np = &n; np = &m; *np = 10; O 16 O 10 O A memory address O 13 True or False? This snippet correctly frees the memory it allocates. int** nums = new int*[10]; for (int i = 0; i < 10; i++) { nums[i] = new int; for (int i = 0; i < 10; i++) { delete nums[i]; delete...
What is the output from running the following code snippet. void mystery(Queue<int>& q) { Stack<int> s; while (!s.isEmptyQueue()) { s.push(q.front()); q.deleteQueue(); } while (!s.isEmptyStack()) { q.addQueue(2 * s.top()); s.pop(); } } Queue q; q.addQueue(8); q.addQueue(4); q.addQueue(18); q.addQueue(7); q.addQueue(5); mystery(q); cout << "["; while (!.isEmptyQueue()) { cout << " " << q.front(); } cout << " ]" << endl;
What number will the following code snippet print? int numbers[8] = { 34, 42, 6, 11, 29, 1, 89, 62}; cout << numbers[7];
What is the output? (3 pts) int num = 5; int* ptr = # cout << ptr << endl; cout << &ptr << endl; cout << *ptr << endl;
The following code snippet is for C++ int selection_Sort(int A[ ], int n) { int I, j, small, temp; for( i = 0; i < n-1; i++) { small = i; for(j = i + 1; j < n; j++) { if ( A[ j ] < A[ small ] small = j; } temp = A [ i ]; A[ i ] = A[small]; A[small] = temp; } } Please explain in rich detail the logic behind every execution...