fabs() Function in C

Learn via video course
FREE
View all courses
C++ Course: Learn the Essentials
C++ Course: Learn the Essentials
by Prateek Narang
1000
5
Start Learning
C++ Course: Learn the Essentials
C++ Course: Learn the Essentials
by Prateek Narang
1000
5
Start Learning
Topics Covered

The fabs in C is a library function provided within the math.h header file of the C programming language. It returns the absolute value of the given input, i.e., it will return the positive value of the given input irrespective of its sign (positive/negative).

Transform Your Career

Choose from our industry-leading programs designed for career success

NSDC Certified

Modern Software and AI Engineering Program

Master full-stack development with AI integration

12 MonthsDuration
AI-LedCurriculum
Career SupportSupport
GoogleAmazonPaytm+1000 more
Go to Program
NSDC Certified

Modern Data Science and ML with specialisation in AI

Advanced data science techniques with AI specialization

12 MonthsDuration
AI-LedCurriculum
Career SupportSupport
GoogleAmazonPaytm+1000 more
Go to Program
NSDC Certified

Advanced AIML with Specialisation in Agentic AI

Deep dive into AIML with focus on Agentic systems

12 MonthsDuration
AI-LedCurriculum
Career SupportSupport
GoogleAmazonPaytm+1000 more
Go to Program
NSDC Certified

DevOps, Cloud & AI Platform Engineering

Build and manage AI-powered cloud infrastructure

12 MonthsDuration
AI-LedCurriculum
Career SupportSupport
GoogleAmazonPaytm+1000 more
Go to Program
NSDC Certified

AI Engineering Advanced Certification by IIT-Roorkee

Premier AI engineering certification from IIT-Roorkee

3 MonthsDuration
AI-LedCurriculum
Career SupportSupport
Program highlights
Go to Program

Syntax of fabs Function in C

Parameters of fabs Function in C

The fabs function in C of the C programming language takes one argument of type double. If you give an input of any other type, say int or float. The C compiler will implicitly convert the input to double.

Free Courses by top Scaler instructors
Python Course for Beginners With Certification: Mastering the Essentials
Java Course - Mastering the Fundamentals
DBMS Course - Master the Fundamentals and Advanced Concepts
JavaScript Course With Certification: Unlocking the Power of JavaScript
C++ Course: Learn the Essentials
Python and SQL for Data Science
Python Course for Beginners With Certification: Mastering the Essentials
Java Course - Mastering the Fundamentals
DBMS Course - Master the Fundamentals and Advanced Concepts
JavaScript Course With Certification: Unlocking the Power of JavaScript
C++ Course: Learn the Essentials
Python and SQL for Data Science

Return Values of fabs Function in C

The return value of the fabs in C function will always be of data type double. Suppose you try to assign the result of a fabs in C function to a variable of any other data type. In that case, the C compiler will implicitly convert the return value of data type double to that of the variable to which it is being assigned.

Scaler Placement Report and Statistics

₹23L
AVG CTC
SCALER PLACEMENT PROOF

Scaler learners achieved 2.5x salary growth with average post-Scaler CTC reaching ₹23L.

11,000+placements
650+companies
Verified data
Hiring Partners:
GoogleGoogleAmazonAmazonMicrosoftMicrosoftFlipkartFlipkartAdobeAdobe1200+ more

Exceptions of fabs Function in C

There is one scenario where the fabs in C function of the C programming language will throw an error. The fabs in C function can not only work with data type int or float inputs. It can also work with inputs of data type char. But the fabs in C cannot work with inputs of string data type. In those situations, the fabs in C will throw an error. So when using inputs of char data type, make sure you always, ALWAYS use single quotes and never double quotes.

ExampleValid / Invalid
fabs in C("a");
fabs in C('a');✔️

Example

Code

Input

Output

As we can see, fabs in C converted the negative floating value -5.0 to a positive floating value 5.000000.

Turn Learning into Career Growth

1200+Hiring Partners
89%Placement Rate
11,000+Placements
147%Avg Salary Increment
2.5XCareer Growth
₹23 LPAAvg Post-Scaler Salary
1200+Hiring Partners
89%Placement Rate
11,000+Placements
147%Avg Salary Increment
2.5XCareer Growth
₹23 LPAAvg Post-Scaler Salary

More Examples of fabs Function in C

The fabs in C function can also work with inputs of int and char data types.

Example 1: fabs in C with int input

Code

Input

Output

Example 2: fabs in C with char input

Code

Output

Like fabs in C, we have abs(), labs() also in math.h which perform similar operation the only difference is that abs() work with int type data and labs() work with long int type data.

Conclusion

  • fabs in C function takes a number as input and returns the magnitude of that number, i.e., ignore the sign of the number and return its absolute value.
  • We must include the math.h header file to use the fabs in C function in C programming.
  • The input can be of the following data types, int, float, char, double for fabs in C function.
  • We can't use inputs of data type string with the fabs in C function.
  • The return value of the fabs in C function will always be that of data type double.