C programming question: Can you please let me know if my work is correct. Also f
ID: 3823912 • Letter: C
Question
C programming question: Can you please let me know if my work is correct. Also for #3 how do you store the answers? Do you always have to set the pointer equal to whatever it needs to do or do you have to flip it so that it equals the pointer?
1. Write the function prototype for the function ProdDiff that takes 2 integers and 2 integer pointers as arguments and returns nothing.
void ProdDiff(int a, int b, int *a, int *b);
2. Write the function call to ProdDiff using integer variables amt1, amt2, prod, and diff that have already been declared and assigned values.
ProdDiff(amt1, amt2, &prod, &diff);
3. Write the function definition for ProdDiff. The function will store the product of the first two integer arguments in the first pointer argument and the difference of the first two integer variables in the second pointer argument. You should not need any other variables than those passed as arguments.
void ProdDiff(int a, int b, int *a, int *b)
{
*a = a*b;
*b = a-b;
}
Explanation / Answer
Solution:
1. void ProdDiff(int amt1,amt2,int *a, int *b);
Note: I have changed the variable names, you cannot have two variables with the same name.
2. ProdDiff(amt1, amt2, &prod, &diff); is correct.
3. Yes , you always have to set the pointer equal to whatever it needs to do.
void ProdDiff(int amt1, int amt2, int *a, int *b)
{
*a = amt1*amt2;
*b = amt1-amt2;
}
So the product of the first two integers will be stored in first pointer argument.
The difference of two integers will be stored in the second pointer argument.
Related Questions
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.