1. ## Small problem

Hello, I'm VERY new to C and started learning today. I have a slight problem, this is my objective:

#5
Write a C program that calls the C function you just wrote in exercise 4 to calculate the multiplication of 3 times 5 and then print out the return value from the function on the screen.
This is what I wrote for the exercise 4 it was talking about:

Code:
```//Function to multiply two ints and return result
#include <stdio.h>
//Multiply two ints
int multiply( int x, int y)
{
int result;
result = x * y;
return result;
}

int main()
{

printf("Ten multiplied by five equals %d.\n", answer);
return 0;
}```
Now, I didn't fully understand what #5 was stating, so can someone help me out? I got this from a tutorial I'm reading. Thanks.

2. Originally Posted by xViBeSz
Hello, I'm VERY new to C and started learning today. I have a slight problem, this is my objective:

#5

This is what I wrote for the exercise 4 it was talking about:

Code:
```//Function to multiply two ints and return result
#include <stdio.h>
//Multiply two ints
int multiply( int x, int y)
{
int result;
result = x * y;
return result;
}

int main()
{

printf("Ten multiplied by five equals %d.\n", answer);
return 0;
}```
Now, I didn't fully understand what #5 was stating, so can someone help me out? I got this from a tutorial I'm reading. Thanks.
what is #5 here. as far as ur code is concerned its fine.

3. umm... sounds like you're finished

Did you know:

Code:
```
int multiply( int x, int y)
{
int result;
result = x * y;
return result;
}```
is equivalent to

Code:
```int multiply( int x, int y)
{
return x * y;
}```
and

Code:
```int main()
{

printf("Ten multiplied by five equals %d.\n", answer);
return 0;
}```
is equivalent to

Code:
```int main()
{
printf("Ten multiplied by five equals %d.\n", multiply( 10, 5) );
return 0;
}```

4. Ohhhhh, so this is the function:

Code:
```int multiply( int x, int y)
{
int result;
result = x * y;
return result;
}```
And this is what calls it?:

Code:
```int main()
{

printf("Ten multiplied by five equals %d.\n", answer);
return 0;
}```
And at above, that looks really weird to me, I'm going to go with what's int he tutorial first and then get shortcuts when I grasp it. Thanks though ^^

5. ## Lil Help

xVibe-

You said

Ohhhhh, so this is the function:

Code:
Code:
```int multiply( int x, int y)
{
int result;
result = x * y;
return result;
}```
And this is what calls it?:
Code:
```int main()
{

printf("Ten multiplied by five equals %d.\n", answer);
return 0;
}```
Hopefully my formatting will work there. Anyway, You are correct. In this case, and in most cases that I have seen thus far, Main calls the function, or series of functions, and they execute, then return to main. Basically, line by line your code executes like this:

2. answer=multiply(10,5); ---- This is the magic of the program. It begins the process of assigning the returned value of the expression to the right of the equals, to the variable at the left. It does this by "calling" the function named multiply, and giving it the values 10 and 5. These are temporarily assigned to the values of x and y you entered in your function header. Control of the program is handed to the multiply function in this step.

3. The multiply function then makes a variable named result.

4. The program assigns the value of x times y to the variable result.

5. The program returns the result and control to the main function. It also assigns the returned value of result to the variable answer (this is the actual point at which that occurs (not step 2, although that step sets the series of events in motion that makes this happen)-it HAS to go through the multiply function first).

6. Print something

7. Return 0 at the end

If there is anything you do not understand please post here or message me. I am not super at coding yet, but I am getting there. Try to avoid learning more than one language at a time, unless you have a photographic memory. That has been my downfall thus far.

Darryl

6. Thank you so much! It covered that in the chapter I was reading, but it was pretty.. vague. Thanks again.

And yeah, I read about subtraction and addition are on a 'lower' thing and multiplication and division and this thing '%' are 'higher'.