C++ perror()

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

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

Overview

The function perror is used to display a string (i.e., description of the error) before the error message stored in errno and displayed in stderr (standard error output stream). The error code stored in errno describes the condition of the error that occurs in the code after the execution.

The errno is a system variable where all the error codes are saved and the condition of the error is produced when the library gets called.

Syntax of C++ perror()

The syntax of the function perror: -

Let us understand the syntax using the following image.

Syntax of C++ perror()

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 Course
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 Course

Parameters of C++ perror()

The function perror only takes one parameter i.e., str which is a pointer that points to the string added before the description of the error.

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

Return Value of C++ perror()

The return type of the function perror is void therefore there is no return value of perror().

Exceptions of C++ perror()

There are no exceptions present for the function perror().

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

How Does C++ perror() Work?

The function perror has a return type of void and takes a string (pointer to a string) as an input. It displays the string entered in the function perror followed by a colon and a space and then the error message that is already saved in the system variable errno and displayed on stderr (i.e., standard error output stream).

Example

Let us look at an example where we will try to access a file that does not exist which will raise an error that is No such file or directory that is already saved in errno. Here, we will add a custom message before the error is printed as given in the following code. After we run the program, the message that we entered in the function gets printed followed by a colon(:) and a space.

Output

After the program is executed, the string entered i.e., "The file does not exist" in the perror() function is displayed before the error description followed by a colon and a space.

Conclusion

  • The perror function is used to display the error message before the error description stored in the system variable errno to stderr (standard error output stream).
  • The perror function takes only one parameter that is a pointer to a string that is added before the error description.
  • There is no return type to the perror function because its return type is void.
  • The string entered in the perror function gets displayed followed by a colon and a space before the error message (the error message is that already saved in system variable errno)