LearnFrenzy
Sign in Take a free test

C Library Functions · Library Functions MCQ · Question 9

abs() vs fabs() in C Answer, explanation & discussion

  • MCQ
  • Easy
  • 0 comments
  • Answer explained
  • Moderated community
Question 9 Back to Exercise

What is the difference between abs() and fabs()?

  • A No difference
  • B abs takes an int (stdlib.h); fabs takes a double (math.h) Correct
  • C fabs is faster
  • D abs works only on positive numbers
Correct Answer: Option B

abs(-2.7) converts the argument to int and returns 2. Use fabs for floating values, labs/llabs for long types.

Discussion & Comments 0

Share your method, a shortcut, or ask about a step you didn't follow.

No comments yet. Be the first to share your solution!

Post your comment

Comments appear after a quick review by our team.

Search LearnFrenzy

Esc

Quick links