### CS1010E Tutorial 2 Q5.

```Using function,
// This is Q5.
// Include preprocessing directive.
#include <stdio.h>
int integerAdd (int x, int y); //Function Prototype for part A.
double doubleAdd (double x, double y); //Function Prototype for part B.
// This programme prints the answer to q5a and q5b.
int main (void)
{
// Declare variable used, where result1 is part1 and result2 is part2.
int result1;
double result2;
//Store the computation in different data type compared to the
function.
// Display the end results from the data type conversion.
printf("result1 = %d\nresult2 = %lf\n", result1, result2);
return 0;
}
int integerAdd (int x, int y)
{
return x+y;
}
double doubleAdd (double x, double y)
{
return x+y;
}
result1 = 10
result2 = 9.000000
Using tracking (part a),
main
:
:
int result;
:
:
return x+y;
(x
4.7
)
(y
5.5
)
( return
10.2 )
( result
10
)
Using tracking (part b),
main
:
:
double result;
:
:
return x+y;
(4.75,5.25);
(x
4
)
(y
5
)
( return
9
)
( result
9.000000 )
 Key
pointers
• Data type conversion will occur automatically
when argument  input parameter (i.e when
4.75  4 in part b)
• Data type conversion will occur automatically
when return value  assignment statement (i.e
when 10.2  10 in part a)
• Precision of result may decreases during the
conversion.
pointer
• No conflict in variable names from function to
function.
Using function,
// This is Q5.
// Include preprocessing directive.
#include <stdio.h>
int integerAdd (int x, int y); //Function Prototype for part A.
double doubleAdd (double x, double y); //Function Prototype for part B.
// This programme prints the answer to q5a and q5b.
int main (void)
{
// Declare variable used, where result1 is part1 and result2 is part2.
int result1;
double result2;
```