Answer to Question #259395 in C for Abhik

Question #259395

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.).


1
Expert's answer
2021-11-01T01:58:21-0400

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

  1. Implicit declaration of built-in function 'round'.

Need a fast expert's response?

Submit order

and get a quick answer at the best price

for any assignment or question with DETAILED EXPLANATIONS!

Comments

No comments. Be the first!

Leave a comment

LATEST TUTORIALS
New on Blog
APPROVED BY CLIENTS