why does we use getchar_unlocked().....?

what does the following code do
register int c = getchar_unlocked();
x = 0;
for(;(c<48 || c>57);c = getchar_unlocked());
for(;c>47 && c<58;c = getchar_unlocked())

1 Like

getchar_unlocked() is considered as a faster method for input and output.
You may refer this link for more details http://stackoverflow.com/questions/24700239/what-is-the-explanation-for-this-piece-of-c-code

1 Like

Getchar_unlocked() increases the speed of getting inputs. It is a thread unsafe version of getchar().
if your program if highly based on speed, use getchar_unlocked(). Otherwise avoid using it.

1 Like