Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 5842401
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 22, 20262026-05-22T12:00:47+00:00 2026-05-22T12:00:47+00:00

Possible Duplicate: How do you printf an unsigned long long int? #include <cstdio> int

  • 0

Possible Duplicate:
How do you printf an unsigned long long int?

#include <cstdio>

int main ()
{
    unsigned long long int n;
    scanf("%llu",&n);
    printf("n: %llu\n",n);
    n /= 3;
    printf("n/3: %llu\n",n);
    return 0;
}

Whatever I put in input, I get very strange output, for example:

n: 1
n/3: 2863311531

or

n: 2
n/3: 2863311531

or

n: 1000
n/3: 2863311864

What’s the reason? How should I do this correctly?

(g++ 3.4.2, Win XP)

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-22T12:00:48+00:00Added an answer on May 22, 2026 at 12:00 pm

    The problem is that MinGW relies on the msvcrt.dll runtime. Even though the GCC compiler supports C99-isms like long long the runtime which is processing the format string doesn’t understand the "%llu" format specifier.

    You’ll need to use Microsoft’s format specifier for 64-bit ints. I think that "%I64u" will do the trick.

    If you #include <inttypes.h> you can use the macros it provides to be a little more portable:

    int main ()
    {
        unsigned long long int n;
        scanf("%"SCNu64, &n);
        printf("n: %"PRIu64"\n",n);
        n /= 3;
        printf("n/3: %"PRIu64"\n",n);
        return 0;
    }
    

    Note that MSVC doesn’t have inttypes.h until VS 2010, so if you want to be portable to those compilers you’ll need to dig up your own copy of inttypes.h or take the one from VS 2010 (which I think will work with earlier MSVC compilers, but I’m not entirely sure). Then again, to be portable to those compilers, you’d need to do something similar for the unsigned long long declaration, which would entail digging up stdint.h and using uint64_t instead of unsigned long long.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Possible Duplicate: Return value from local scope? #include <stdio.h> int main() { int x
Possible Duplicate: strange output in comparision of float with float literal #include<stdio.h> int main()
Possible Duplicate: How to printf “unsigned long” in C? I have my number like
Possible Duplicate: What’s the “condition” in C interview question? void main() { if(CONDITION) printf(Hello
Possible Duplicate: What does “#define STR(a) #a” do? #include <stdio.h> #define f(a,b) printf(yes) #define
Possible Duplicate: Print leading zeros with C++ output operator (printf equivalent)? #include <iostream> #include
Possible Duplicate: Why #include <stdio.h> is not required to use printf()? Both printf and
Possible Duplicate: Is there a printf converter to print in binary format? Consider this
Possible Duplicate: Pre & post increment operator behavior in C, C++, Java, & C#
Possible Duplicate: Why does printf not flush after the call unless a newline is

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.