2
#include<bits/stdc++.h>

#define ll long long

using namespace std;

int main()
{
    ll n;
    while(scanf("%lld",&n) != EOF) 
    {
        printf("hello\n");
    }
    return 0;
}

// When i input a non integer, the loop runs infinitely, which i think it should not. Can someone please explain?

Satyam Garg
  • 156
  • 9
  • 2
    `scanf` will not consume anything from the input stream if it fails to parse and `EOF` is not returned in that case -> your loop constantly tries to parse the input, fails to do it (returns 0) and just repeats the `scanf` on the same input – UnholySheep Dec 30 '16 at 09:35
  • @UnholySheep thnxx – Satyam Garg Dec 30 '16 at 09:45
  • 1
    The dupe is a C question but it is the same problem (scanf having the same behaviour in both languages) – M.M Dec 30 '16 at 09:52

0 Answers0