What is the right way to use errno?



What is the right way to use errno?..

Answer / Ankur Mittal

In C, errno is a global variable that holds the error number of the last system error. To use it correctly, first call a function that might return an error (like fopen(), read(), write(), etc.), then check if it returned NULL or an error code, and if so, print the error message using perror("message"), which prints the string corresponding to errno.

Is This Answer Correct ?    0 Yes 0 No

Post New Answer

More C Interview Questions

What are variables c?

1 Answers  


How can I send mail from within a c program?

1 Answers  


What is 'bus error'?

1 Answers  


What is variable in c example?

1 Answers  


write a program to display the array elements in reverse order in c language

16 Answers  


Why do we use & in c?

1 Answers  


what is difference between overriding and overloading?

1 Answers  


Read N characters in to an array . Use functions to do all problems and pass the address of array to function. 1. Print only the alphabets . If in upper case print in lower case vice versa.

1 Answers  


class foo { public: static int func(const char*& p) const; }; This is illegal, why?

8 Answers   Google,


How can I implement opaque (abstract) data types in C? What's the difference between these two declarations? struct x1 { ... }; typedef struct { ... } x2;

2 Answers  


Explain how are 16- and 32-bit numbers stored?

1 Answers  


What is ctrl c called?

1 Answers  


Categories