1answer.
Ask question
Login Signup
Ask question
All categories
  • English
  • Mathematics
  • Social Studies
  • Business
  • History
  • Health
  • Geography
  • Biology
  • Physics
  • Chemistry
  • Computers and Technology
  • Arts
  • World Languages
  • Spanish
  • French
  • German
  • Advanced Placement (AP)
  • SAT
  • Medicine
  • Law
  • Engineering
tester [92]
3 years ago
8

Write the definition of a function divide that takes four arguments and returns no value . The first two arguments are of type i

nt . The last two arguments arguments are pointers to int and are set by the function to the quotient and remainder of dividing the first argument by the second argument . The function does not return a value .The function can be used as follows:int numerator=42, denominator=5, quotient, remainder; divide(numerator,denominator,&quotient,&remainder); / quotient is now 8 / / remainder is now 2 /
Computers and Technology
1 answer:
Nastasia [14]3 years ago
8 0

Answer:

#include <iostream>

using namespace std;

void divide(int numerator, int denominator, int *quotient, int *remainder)

{

*quotient = (int)(numerator / denominator);

*remainder = numerator % denominator;

}

int main()

{

int num = 42, den = 5, quotient=0, remainder=0;

divide(num, den, &quotient, &remainder);

 

return 0;

}

Explanation:

The exercise is for "Call by pointers". This technique is particularly useful when a variable needs to be changed by a function. In our case, the quotient and the remainder. The '&' is passing by address. Since the function is calling a pointer. We need to pass an address. This way, the function will alter the value at the address.

To sum up, in case we hadn't used pointers here, the quotient and remainder that we set to '0' would have remained zero because the function would've made copies of them, altered the copies and then DELETED the copies. When we pass by pointer, the computer goes inside the memory and changes it at the address. No new copies are made. And the value of the variable is updated.

Thanks! :)

You might be interested in
add is a method that accepts two int arguments and returns their sum. Two int variables, euroSales and asiaSales, have already b
Oduvanchick [21]

Answer:

// here is code in Java.

// package

import java.util.*;

// class definition

class Main

{

   // method that return sum of two sale value

   public static int Add(int euroSales,int asiaSales)

   {

       // return the sum

       return euroSales+asiaSales;

   }

   //main method of the class

public static void main (String[] args) throws java.lang.Exception

{

   try{

    // variables

       int euroSales=100;

       int asiaSales=150;

       int eurasiaSales;

        // call the function

       eurasiaSales=Add(euroSales,asiaSales);

        // print the sum

       System.out.println("total sale is:"+eurasiaSales);

   }catch(Exception ex){

       return;}

}

}

Explanation:

Declare and initialize two variables "euroSales=100" and "asiaSales=150". Declare another variable eurasiaSales. Call the method Add() with euroSales and asiaSales as parameter. This method will add both the value and return the sum.This sum will be assigned to variable eurasiaSales.Then print the sum.

Output:

total sale is:250  

8 0
4 years ago
Define las 3 fases de la economia y explica en que espacios se localizan​
navik [9.2K]
Can you like translate it to English so I can understand lol
7 0
3 years ago
Pointers are addresses and have a numerical value. You can print out the value of a pointer as cout &lt;&lt; (unsigned)(p). Writ
lukranit [14]

Answer:

#include <iostream>

using namespace std;

int main() {

  int i = 2;

  double j = 3;

 

  int *p = &i;

  double *q = &j;

 

  cout << "p = " << p << ", p+1 = " << p+1 << endl;

  cout << "q = " << q << ", q+1 = " << q+1 << endl;

  return 0;

}

Explanation:

In C++, pointers are variables or data types that hold the location of another variable in memory. It is denoted by asterisks in between the data type and pointer name during declaration.

The C++ source code above defines two pointers, "p" which is an integer pointer and "q", a double. The reference of the variables i and j are assigned to p and q respectively and the out of the pointers are the location of the i and j values in memory.

8 0
3 years ago
Imagine that the United States is characterized by a political structure in which the state government and the national governme
Alenkinab [10]

Answer:

The answer is " Co-operative federalism".

Explanation:

It is also known as Marble-cake governance, this federalism provides an idea, in which both governments (state and local), works together and productively resolves the common issues, that are distinct, but mostly identical.

  • It provides disagreement, over a policy in a national system, that is governed by the federal state.
  • It supports fitness, that's why the Co-operative federalism is the correct answer.
6 0
3 years ago
Why do we use modem while<br>accessing the internet or email​
Dafna1 [17]

Answer: Modems: Your gateway to the internet

To bring the internet into your home, you're going to need a modem. This is a small device that connects to your internet service provider (ISP) to tap into all that internet goodness. ... Your modem shares this connection with a computer or a router via an Ethernet cable.

Explanation:

7 0
4 years ago
Other questions:
  • Unlike a virtual image, a real image
    7·1 answer
  • Peter has recently bought a media player and a digital camera. He wants to buy a memory card for these devices. Which memory dev
    12·2 answers
  • Can you know what time someone retweeted
    5·1 answer
  • Browsing the web is one of the most common activities performed by individuals who use computers.
    12·1 answer
  • Which of the following best describes the displayport interface used for connecting video monitors to computers
    11·1 answer
  • Which payment method typically charges the highest interest rates everfi
    6·1 answer
  • Can anyone please help me to solve this question?
    10·1 answer
  • Pleasee help. How do you fix this problem in discord?
    10·1 answer
  • 2. Which of the following is not one of the guidelines for using instant messaging?A.You can use in place of all face-to-face co
    12·1 answer
  • Multinational corporations use __ to share their resources with all their employees because it __
    11·1 answer
Add answer
Login
Not registered? Fast signup
Signup
Login Signup
Ask question!