dimanche 3 mai 2020

Inline function for taking input in C++

While browsing answers to problems in competitive coding, I usually come across this inline function called read(). After looking at the main function, I understood that it is used to take inputs. But I cant really understand what each line means. Here is the function

inline int read() {
int x = 0, f = 1; char ch = getchar();
while(ch > '9' || ch < '0') { if(ch == '-') f = -1; ch = getchar(); }
do x = x * 10 + ch - 48, ch = getchar(); while(ch >= '0' && ch <= '9');
return x * f;

}

What is it returning? What do the if statements do? This is the link to the full code

Aucun commentaire:

Enregistrer un commentaire