Wierd output after sorting

I am getting weird output after sorting

If giving input using scanf the line is causing error. The output is in some weird arrangement. (I have commented the line)

If I use cin the output is fine. Also the problem is not present in online compilers. Same thing is happening on different computers.

Eg if I input

23 44 32 2 233

the output is

32 23 233 2 44


#include <iostream>
#include <cstdio>
#include <cstring>
#include <cmath>
#include <algorithm>
#include <iomanip>

using namespace std;

int main() {

    unsigned long long int n=0,i=0;


    unsigned long long int arr[n];

      //cin>>arr[i]; //if use this no error but if use next line it is
      scanf("%llu",&arr[i]); //causing error


//      cout<<arr[i]<<" ";
printf("%llu ",arr[i]);
return 0;

Source: c++

Leave a Reply

This site uses Akismet to reduce spam. Learn how your comment data is processed.