You are not logged in. Please login at www.codechef.com to post your questions!

×

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())

asked 14 Oct '14, 15:10

panther527's gravatar image

1★panther527
41138
accept rate: 33%


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

link

answered 14 Oct '14, 15:19

rishabhprsd7's gravatar image

2★rishabhprsd7
1.9k11243
accept rate: 14%

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.

link

answered 14 Oct '14, 15:27

arvindkr's gravatar image

1★arvindkr
182
accept rate: 0%

edited 14 Oct '14, 15:28

toggle preview
Preview

Follow this question

By Email:

Once you sign in you will be able to subscribe for any updates here

By RSS:

Answers

Answers and Comments

Markdown Basics

  • *italic* or _italic_
  • **bold** or __bold__
  • link:[text](http://url.com/ "title")
  • image?![alt text](/path/img.jpg "title")
  • numbered list: 1. Foo 2. Bar
  • to add a line break simply add two spaces to where you would like the new line to be.
  • basic HTML tags are also supported
  • mathemetical formulas in Latex between $ symbol

Question tags:

×19

question asked: 14 Oct '14, 15:10

question was seen: 919 times

last updated: 14 Oct '14, 15:28