Link to home
Start Free TrialLog in
Avatar of jenmaz
jenmaz

asked on

pointers and invoking functions???

I have 2 questions on pointers.  I am not sure how to answer.

1. Question deals with pointing the smallest of 3 integers to one pointer.
Given the integer variables  x ,  y , and  z , write a fragment of code that assigns the smallest of  x ,  y , and  z to another integer variable  min .
 Assume that all the variables have already been declared and that  x ,  y , and  z have been assigned values).

Here was my answer that I know is wrong.
[c]
int minimum (x,y,z)
{
if (x<y)
{
min=x;
}
else
{
min=y;
}
if (min<z)
{
min;
}
else
{
min=z;
}
return min;
}


int maximum (x,y,z)

{
if (x>y)
{
int max;
max=x;
}
else
{
max=y;
}
if (max>z)
{
max;
}
else
{
max=z;
}
return max;
}
[/c]


2. I am having trouble "invoking a function.

Here is my question and I have to be honest I do not know how to answer.

eroIt is a function that takes one argument and returns no value. The argument is a pointer to  int . The function stores the value 0 back into the variable pointed to by the argument.
 x is an  int variable that has been declared. Write a statement that sets the value stored in  x to zero by invoking the function  zeroIt .

Avatar of jkr
jkr
Flag of Germany image

The latter one is quite easy to handle - you take the address of an 'int' and pass it to the function, e.g.

void zeroIt(int* p) {

  *p = 0;
}

Finding the min/max values can be a lot easier, too:

int maximum ( int x, int y, int z) {

  int max = 0;

  if ( x > max) max = x;
  if ( y > max) max = y;
  if ( z > max) max = z;

  return max;
}

The minimum is the part I'll leave to you so that you at least can lear a bit from your piece of homework :o)
Avatar of jenmaz
jenmaz

ASKER

Hi there,

I attempted to answer both as you have answered me earlier today and this is not right.  The answer should call a function (which I am not sure how to do) and the other is not right because I am just suppose to find the min of the x, y z and assign min to the smallest. So this does not help me either.

Thanks any ways.

Jennifer
SOLUTION
Avatar of jkr
jkr
Flag of Germany image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
ASKER CERTIFIED SOLUTION
Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial