Question

Here is a function that takes, and returns pointers: 2 int* select(bool which, int* a, int*...

Here is a function that takes, and returns pointers:

2

int* select(bool which, int* a, int* b) {
    if(which == true)
        return a;
    else
        return b;
}

Using this function, suppose we have variables x, y:

int x = ..., y = ...;

int* p = select(x < y, &x, &y);
if(p == &x)
    cout << "Yes";
else
    cout << "No";
  • What will this print if x = 5, y = 7?

  • What will this print if x = 23, y = 9?

0 0
Add a comment Improve this question Transcribed image text
Answer #1

What will this print if x = 5, y = 7?

OUTPUT: Yes

What will this print if x = 23, y = 9?

OUTPUT: No

Add a comment
Know the answer?
Add Answer to:
Here is a function that takes, and returns pointers: 2 int* select(bool which, int* a, 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
  • • bool test(int a, int& b) { bool res = false; if(a > b) { b...

    • bool test(int a, int& b) { bool res = false; if(a > b) { b = a%2; res = true; } return res; } int main() { int x = 45, y = 43; test(x, y); cout << x << " " << y << endl; return 0; } Question: The output of the above code is: ________________ •Write a function that takes an integer as its sole parameter and returns -1, 0 or 1 depending upon whether the...

  • a) Make a function which returns x/3 with a given integer x. double third(int x) {...

    a) Make a function which returns x/3 with a given integer x. double third(int x) { //Complete your code below. ______________________________________ return y; } b) Make a program which shows 2 ∗ n with a given user input n. #include<iostream> using namespace std; // Complete the blank. _______________________ int main(){ int n; cout<<"Enter:"; cin>>n; cout<<twice(n); return 0; } int twice(int x){ return 2*x; } c) Make a function which returns true if n is positive, otherwise returns false. ________ positive(int...

  • QUESTION 1 What is the output of the following code snippet? int main() { bool attendance...

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

  • In C++ #include<iostream> using namespace std; //Implement the function below. bool is_fibonacci_array(int*,int); //Param 1: pointer to...

    In C++ #include<iostream> using namespace std; //Implement the function below. bool is_fibonacci_array(int*,int); //Param 1: pointer to the beginning of an array of integers //Param 2: size of that array //Returns: true, is every element in the input array is a Fibonacci number //(the order of the numbers in the array need not be ordered //as per the Fibonacci sequence) //false, otherwise //A Fibonacci sequence is generated as follows. //The first two numbers in the sequence are 0 and 1. //The...

  • Write a generic function int find_lower_bound(T seq[], int n, const T& value). The function returns the...

    Write a generic function int find_lower_bound(T seq[], int n, const T& value). The function returns the index of the largest element in the given sequence that is less than the given value. If multiple elements satisfy, return the one with smallest index. Return -1 if no such element exists. //main.cpp #include<iostream> #include<string> #include<vector> #include<algorithm> using namespace std; #include "source.h" struct Point{    int x,y;    bool operator<(const Point& p) {        return (x<p.x || (x==p.x&&y<p.y));    } }; int...

  • In C++ Write a function int * return_matches(int a[], int & size,TEST t) which returns an...

    In C++ Write a function int * return_matches(int a[], int & size,TEST t) which returns an array (allocated off of the heap in the function) containing only the elements of array a that pass the “test” t. The function iterates through all the elements of a, and constructs a new array containing all the elements that pass the test. When the parameter corresponding to “size” is passed in (by reference), it contains the size of the array a. In the...

  • Using C++ Question#1: isPalíndrome Write the following function: bool isPalindrome(int) takes an integer and returns true...

    Using C++ Question#1: isPalíndrome Write the following function: bool isPalindrome(int) takes an integer and returns true if that integer is palindrome, otherwise it returns false. The function also prints the digits of the integer in reverse order in which they were found. Write a main) function that reads an integer, calls the function is whether the integer is a palindrome or not. Palindrome), and prints Sample input/output: nter an integer: 23434 nter an integer 23432 3434 is not a palindrome...

  • A_____error causes the program to prematurely terminate during execution. ==.!=.>.<= are examples of____operators. A_____loop always executes...

    A_____error causes the program to prematurely terminate during execution. ==.!=.>.<= are examples of____operators. A_____loop always executes its body at least once. The function_______lets the compiler know that the function will be defined later. The_____statement skips to the end of the body of a loop. The_____loop has a header which consists of three sections separated by semicolons. The____of an infinite loop is always true. A(n)____statement cannot exist without an if statement. The_____of a variable tells the compiler which values it can...

  • Haskell code: checkIfEven :: Int -> Bool x <- readLn let checkIfEven x = (even ((x*3)+1))...

    Haskell code: checkIfEven :: Int -> Bool x <- readLn let checkIfEven x = (even ((x*3)+1)) print checkIfEven    Getting error :  Variable not in scope: checkIfEven :: Int -> Bool, how to fix it? note: function goal is take an int and return a bool. takes the integer multiplies it by 3 and adds 1. if the the outcome is even return true, otherwise false.

  • I need assistance with the C++ code below to remove the "this" pointers while maintaining the...

    I need assistance with the C++ code below to remove the "this" pointers while maintaining the code's current output and functionality. Also, there should be a private class in the header file, but I'm not sure what I should include there. Any help would be greatly appreciated! ***main.cpp driver file*** #include <iostream> #include "vector.h" using namespace std; int main() {   vectorInfo v1(7, 6);   vectorInfo v2(5, 4);       v1.set(3, 2);   cout << "v1 : ";   v1.print();       cout << "v2 :...

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