Code360 powered by Coding Ninjas X Naukri.com. Code360 powered by Coding Ninjas X Naukri.com
Table of contents
1.
Introduction
2.
isinf() function
3.
Examples
4.
Frequently Asked Questions
4.1.
What is C++ programming language?
4.2.
In which header file, is the isinf() function present?
5.
Conclusion
Last Updated: Mar 27, 2024
Easy

isinf() function in C++

Author APURV RATHORE
0 upvote
Leveraging ChatGPT - GenAI as a Microsoft Data Expert
Speaker
Prerita Agarwal
Data Specialist @
23 Jul, 2024 @ 01:30 PM

Introduction

C++ is a computer language that supports both imperative and object-oriented programming. Middle-level programming language is another name for it. Bjarne Stroustrup has been working on it at Bell Labs since 1979. It was published for the first time in 1985. It is a free-form programming language that is compiled, general-purpose, statically typed, and case sensitive. Learning C++ not only makes the basics of programming much stronger but also opens the path to various career opportunities. 

A professional C++ programmer must be familiar with the various inbuilt functions that the language provides.  In this blog, we'll look at the isinf() function in C++, its syntax, how it works, and what its return result is.

Also see, Literals in C, Fibonacci Series in C++

isinf() function

isinf() is a built-in function in C++ that resides in the header file of MATH that checks if the variable handed in is infinite or not, regardless of whether the value is negative or positive infinity. The function returns a non-zero result (true) if the number is infinite, and zero if it is not (false). If the number is NAN, the method will likewise return 0.

Syntax:

bool isinf(float n);
bool isinf(double  n);
bool isinf(long double n);

One important characteristic of the isinf function is that it accepts only floating-point numbers. 

The function returns a boolean value, with 0 indicating false (not infinity) and 1 indicating true (infinite).

Also Read - C++ Interview Questions

Get the tech career you deserve, faster!
Connect with our expert counsellors to understand how to hack your way to success
User rating 4.7/5
1:1 doubt support
95% placement record
Akash Pal
Senior Software Engineer
326% Hike After Job Bootcamp
Himanshu Gusain
Programmer Analyst
32 LPA After Job Bootcamp
After Job
Bootcamp

Examples

Example 1:

#include <iostream>  
#include<math.h>  
using namespace std;  
int main()  
{  

   float x=1.0/0.0;  
   // as any number divided by 0 is 0, hence x will be infinity
   cout<<"Is x infinity : "<<isinf(x);  
   return 0;  
}  

 

Output:

Is x infinity : 1

 

In the above example, we divide 1 by 0. Hence, as any number divided by 0 is 0, hence x will be infinity.

Example 2:

#include <iostream>  
#include<math.h>  
using namespace std;  
int main()  
{  

   float x=4;  
   // as 4 is not infinity, hence the code outputs 0
   cout<<"Is x infinity : "<<isinf(x);  
   return 0;  
}  

 

Output:

Is x infinity : 0

 

In the above example, as 4 is not infinity, hence the code outputs 0.

Try and compile with online c++ compiler.

Must Read C++ vs Java

Frequently Asked Questions

What is C++ programming language?

C++ is an object-oriented programming language that offers programs a clear structure and promotes code reuse, which reduces development costs. C++ is a portable programming language that may be used to create cross-platform programs.

In which header file, is the isinf() function present?

isinf() function is present in the MATH header file in C++. 

Conclusion

In this article, we have extensively discussed the isinf() function in detail along with various examples in C++ programming language. We hope that this blog has helped you enhance your knowledge regarding the C++ programming language and if you would like to learn more about the C++ programming language, check out this article on basics to C++You can refer to our guided paths on the Coding Ninjas Studio platform to learn more about DSA, DBMS, Competitive Programming, Python, Java, JavaScript, etc. To practice and improve yourself in the interview, you can check out Top 100 SQL problemsdata structure courseCoding interview questions, and the Ultimate guide path for interviews. Do upvote our blog to help other ninjas grow. 

Happy Coding!

Live masterclass