Skip to main content

What is the difference between EOF and NULL

EOF and NULL are standard defines which normally equate to an integer value,


NULL is always 0

EOF   is compiler dependent         most commonly its -1 (in gcc & g++ it is -1).


Functions that are defined to return a pointer (like fgets()) typically return NULL to indicate that an exceptional condition has prevented them from doing their usual job. NULL is used because it is not a value that the function could ever return in the normal, successful case. The only time the function will return NULL is when something strange happened.

Functions that are defined to return an integer (like fscanf()) typically return EOF when something exceptional happens. Functions that do this do it because EOF is a value that can not possibly occur in the normal case where the function was able to succeed at doing whatever it was supposed to do. The EOF value is unambiguous.

So, generally you can figure out whether you should be looking for NULL or for EOF by considering the return type of the function. However, it's always a good idea to check the documentation because it's possible that there could be several conditions that might cause the function to return one of these distinctive values. End-of-file is not the only possible cause.

BTW, a scary thing about those code fragments is that they do not check the result of fopen(). (Incidentally, since fopen() returns a pointer you'd expect it to return NULL if it fails. That's exactly what it does.) In a real program you would always, always check that return value.

Comments

Popular posts from this blog

ORACLE 9i practice solutions

Created by BCL easyConverter SDK 3 (HTML Version)

Zoho Puzzle Questions With Answers

Measuring Time Logic Puzzle You are given with two ropes with variable width. However if we start burning both the ropes, they will burn at exactly same time i.e. an hour. The ropes are non-homogeneous in nature. You are asked to measure 45 minutes by using these two ropes.

How can you do it?

Please note that you can’t break the rope in half as it is being clearly stated that the ropes are non-homogeneous in nature.
Answer & Explanation Solution: 45 minutes

Explanation :
All you have to do is burn the first rope from both the ends and the second rope from one end only simultaneously. The first rope will burn in 30 minutes (half of an hour since we burned from both sides) while the other rope would have burnt half. At this moment, light the second rope from the other end as well. Where, the second rope would have taken half an hour more to burn completely, it will take just 15 minutes as we have lit it from the other end too.

Thus you have successfully calculated 30+15 = 45 minutes …

Hackerrank > SQL > Basic Select

Select
01-Select All
Given a City table, whose fields are described as +-------------+----------+ | Field       | Type     | +-------------+----------+ | ID          | int(11)  | | Name        | char(35) | | CountryCode | char(3)  | | District    | char(20) | | Population  | int(11)  | +-------------+----------+
write a query that will fetch all columns for every row in the table.

My Solution
SELECT*FROM city;
---------------------------------------------------------------------------------
02-Select by ID
Given a City table, whose fields are described as