Question

C++

1.
A?B?C?D? which one is correct
#include<iostream> using namespace std; void swap0(int* ptri, int* ptr2) { int *temp; temp = ptr1; ptr1 = ptr2; ptr2 = temp;

2.

What of the following statement is correct when using bubble sort to make an array of n elements in an ascending order? (Assu

3A, 3B

600 vu WNP #include<iostream> int* foo(int x){ int z = x*x; std::cout << &z << std::endl; return &z; int main() { int x = 100which line can free the space correctly? int* foo(int x){ int *y = new int [x*x]; return y; int main() { int * z = foo(10); /

0 0
Add a comment Improve this question Transcribed image text
Answer #1
Question 1:
swap3 is correct.
Option D

Question 2:
After iterating the first outer loop, the largest number can always be fixed;
Question 3:
Foo function returns a pointer which points to a local variable.
Question 4:

delete z:

Add a comment
Know the answer?
Add Answer to:
C++ 1. A?B?C?D? which one is correct 2. 3A, 3B #include<iostream> using namespace std; void swap0(int*...
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
  • #include <iostream> using namespace std; struct node { int base=0; int power=0; }; void insert(node ptr[],int...

    #include <iostream> using namespace std; struct node { int base=0; int power=0; }; void insert(node ptr[],int basee,int powerr) { ptr[powerr].power=powerr; ptr[powerr].base=basee; } void subtract(node ptr1[],int size1,node ptr2[],int size2,node ptr3[]) { for(int j=0;j<=size1;j++) { if(ptr1[j].base!=0) { ptr3[j].base=(ptr3[j].base)+(ptr1[j].base); ptr3[j].power=ptr2[j].power; } } for(int j=0;j<=size2;j++) { if(ptr2[j].base!=0) { ptr3[j].base=(ptr3[j].base)-(ptr2[j].base); ptr3[j].power=ptr2[j].power; } } } void addition(node ptr1[],int size1,node ptr2[],int size2,node ptr3[]) { for(int j=0;j<=size1;j++) { if(ptr1[j].base!=0) { ptr3[j].base=(ptr3[j].base)+(ptr1[j].base); ptr3[j].power=ptr2[j].power; } } for(int j=0;j<=size2;j++) { if(ptr2[j].base!=0) { ptr3[j].base=(ptr3[j].base)+(ptr2[j].base); ptr3[j].power=ptr2[j].power; } } } void display(node ptr[],int size)...

  • Please help me debug the following code #include int main(void){ int a = 11, b =...

    Please help me debug the following code #include int main(void){ int a = 11, b = 5; int *ptr1 = &a, *ptr2 = &b; printf("%d %d\n", *ptr1, *ptr2); swap(&ptr1, &ptr2); printf("%d %d\n", *ptr1, *ptr2); minimum(ptr1, ptr2); printf("%d %d\n", a, b); return 0; } // Part A void swap(int **ptr1, int **ptr2){ int *temp = *ptr1; *ptr1 = *ptr2; *ptr2 = temp; return; } // Part B void minimum(int *ptr1, int *ptr2){ if(*ptr1 > *ptr2){ *ptr1 = *ptr2; }else{ *ptr2 =...

  • Explain the results 푤include using nanespace std: int nain (O rloat arr[s- (12.5,.11.0, 13.8, 1...

    Explain the results 푤include <iostream> using nanespace std: int nain (O rloat arr[s- (12.5,.11.0, 13.8, 1000.5, 1.5): float ptri-arEIo1: float *ptr2"ptri +3: cout<< +ptr2xcend *ptr2-* (ptr2)+1: //Line 16 cout<< ptr2<<endl: return 0; Bxplaing the results. 5 What Happens if the Line 16 is replaced by *ptr2- (ptr2+1): 6. tincludekiostream> using namespace std: void fun (int arr(I) int for air size = arestizer) isizeor (arr10]); for (i=0;遠くarr size: i++) int main(0 int int array 114](10, 20 30, 401 fun (array 1):...

  • #include <iostream> using namespace std; int main(void) {    int SIZE;    cout<<"Enter the size of the...

    #include <iostream> using namespace std; int main(void) {    int SIZE;    cout<<"Enter the size of the array"<<endl;    cin>>SIZE;     int *numlist = new int[SIZE];     // Read SIZE integers from the keyboard     for (int i = 0; i<SIZE; i++ )    {        cout << "Enter value #" << i+1 << ": ";        cin >> numlist[i];     }     // Display the numbers in a reverse order     for (int i = SIZE; i > 0; i--...

  • #include <iostream> using namespace std; struct node { int base; int power; }; void insert(node ptr[],int...

    #include <iostream> using namespace std; struct node { int base; int power; }; void insert(node ptr[],int basee,int powerr) { ptr[powerr].power=powerr; ptr[powerr].base=basee; } void addition(node ptr1[],int size1,node ptr2[],int size2,node ptr3[],int size3) { for(int j=0;j<=size1;j++) { ptr3[j].base=ptr3[j].base+ptr1[j].base; } for(int j=0;j<=size2;j++) { ptr3[j].base=ptr3[j].base+ptr2[j].base; } } void display(node ptr[],int size) { if(ptr[0].base!=0) cout<<ptr[0].base<<"+"; for(int i=1; i<=size; i++) { if(ptr[i].base!=0) cout<<ptr[i].base<<"x^"<<ptr[i].power<<"+"; } } int main() { bool choice1=true; bool choice2=true; int size1,size2,base1,base2,power1,power2; cout<<"enter the max power in polynominal 1"; cin>>size1; node *a= new node[size1+1]; for(int...

  • what is the output for the following code? explain the steps. /*#include <iostream> using namespace std;...

    what is the output for the following code? explain the steps. /*#include <iostream> using namespace std; int f(int &i) { i = 10; return(5 * i); } int main() { int n = 5; f(n); cout << n << "\n"; return 0; } #include <iostream> using namespace std; int sub1(int n) { n--; return n; } int main() { int m = 10; for(int j = 0; j < 10; j++) m -= sub1(j); cout << m << "\n"; return...

  • What is the difference between these two programs? #include <iostream> using namespace std; int DontPanic(int &...

    What is the difference between these two programs? #include <iostream> using namespace std; int DontPanic(int & x); int z = 10; void main() { char x = 'y'; int y = 5; int z = 100; y = DontPanic(z); cout << x << " " << y << " " << z << endl; } int DontPanic(int & x) { int * p; p = & z; x = (*p)++ + 1; cout << x << " " << *p...

  • Consider the following C++ program: #include <iostream> using namespace std; void f1(int); void f2(int); void f3(int);...

    Consider the following C++ program: #include <iostream> using namespace std; void f1(int); void f2(int); void f3(int); int main() { f1(10); return 0; } void f1(int n) { f2(n + 5); } void f2(int n) { f3(n - 2); } void f3(int n) { cout << n << endl; // LINE 1 } Just before the program statement marked with the comment "LINE 1" is executed, how many stack frames will be on the program call stack?

  • #include <iostream> using namespace std; const int SIZE = 10; void displayGreaterThan(int[], int); void displaySmallerThan(int[],int); void...

    #include <iostream> using namespace std; const int SIZE = 10; void displayGreaterThan(int[], int); void displaySmallerThan(int[],int); void displayArrayContent(int[]); void displayLargestValue(int[]); void displaySmallestValue(int[]); int main(){    int number;    int numbers[SIZE] = {9,1,90,98,53,22,76,29,37,65}; cout <<"Enter a number: "; cin >> number; cout << endl;    displayGreaterThan(numbers,number); cout << endl; displaySmallerThan(numbers,number); cout << endl; displayArrayContent(numbers); cout << endl; displayLargestValue(numbers); cout << endl; displaySmallestValue(numbers); cout << endl;    return 0;       } void displayGreaterThan(int value[],int num){ cout << " All larger value(s)than" <<...

  • C++ question #include <iostream> using namespace std; void printReverse(int); int main() {     int number = 12345;...

    C++ question #include <iostream> using namespace std; void printReverse(int); int main() {     int number = 12345;     cout << "Original : " << number << endl;     cout << "Reversed : ";     printReverse(number); } void printReverse(int x) {     if (x == 0)        return;     cout << x % 10;     printReverse(x /= 10);     } Modify the above recursive program to output the number in the same order. Note that the program still should break up the number and then output it in the...

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
ADVERTISEMENT