Try to compile the following code snippet (no need to link).
char add(float a,float b)
{
return (int)(round (a)+round (b)) ;
}
Would the compilation of this code snippet result in errors or warnings?
Would this code, if compiled and linked with a full fledged program result in
any logical errors? Answer both parts accurately.
What to submit:
• Command (with appropriate arguments) that were used to compile the
snippet.
• A writeup showing all the compilation errors and warnings that you may
have encountered and their possible explanations, along with the logical
errors (if any if you think there are, i.e.).
Command used to compile the snippet
#include<math.h>
#include <stdio.h>
char add(float a,float b)
{
return (int)(round (a)+round (b)) ;
}
int main()
{char m,n;
int p=add(m,n);
printf("%c",p);
return 0;
}
The code will result in warnings.
When the code is compiled and linked with a full fledged program it will not result in
any logical errors since an int is used which cannot over flow max sum of two chars or bytes.
Errors and warnings encountered
Comments
Leave a comment