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

  • Home
  • SEARCH
  • 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 7978231
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 4, 20262026-06-04T09:26:02+00:00 2026-06-04T09:26:02+00:00

I have a problem while using the printf function to print values of type

  • 0

I have a problem while using the printf function to print values of type unsigned long long int

I have no idea what’s wrong. I’m using Dev-Cpp 4.9.9.2 and Visual Studio 2010 Professional (I know that it’s not C compiler, but anyway, wanted to try) on Windows 7 Professional 64-bit. For displaying, I used %llu modifier (according to How do you printf an unsigned long long int(the format specifier for unsigned long long int)?) but I also tried I64d with no effect…


Firstly, I just wanted to print minimum and maximum value of unsigned long long int (using ULONG_MAX from limits.h)

printf("unsigned long long int: \n%llu to %llu \n\n", 0, ULONG_MAX);

Returns:

unsigned long long int: 18446744069414584320 to 1580552164021 (Dev-Cpp)

unsigned long long int: 18446744069414584320 to 0 (Visual Studio)


Then I tried to using printf to print two zeros

printf("unsigned long long int: \n%llu to %llu \n\n", 0, 0);

Returns:

unsigned long long int:
0 to 1580552164021 (Dev-Cpp)

unsigned long long int: 0 to 0 (Visual Studio)


Also tried two ULONG_MAX values

printf("unsigned long long int: \n%llu to %llu \n\n", ULONG_MAX, ULONG_MAX);

Returns:

unsigned long long int: 18446744073709551615 to 1580552164021 (Dev-Cpp)

unsigned long long int:
18446744073709551615 to 0 (Visual Studio)


Why does it behave like that? Could you explain it to me?

  • 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-06-04T09:26:04+00:00Added an answer on June 4, 2026 at 9:26 am

    This is wrong:

    printf("unsigned long long int: \n%llu to %llu \n\n", 0, ULONG_MAX);
    

    You use a unsigned long long format specifier, but you pass an int and an unsigned long value. Promotion rules mean you can be sloppy for everything int-sized or smaller, which does not apply to long long.

    Use casts:

    printf("unsigned long long int: \n%llu to %llu \n\n",
           0ULL, (unsigned long long) ULONG_MAX);
    

    Explanation: When passing arguments to printf, any type that can fit in an int is promoted to int, and then any type that can fit in an unsigned int is promoted to unsigned int. It is also okay to pass an unsigned type to a signed format specifier or vice versa as long as the value passed can be represented using the type specified by the format specifier.

    So you must be careful with long and long long, but you can be sloppy with int, short, and char.

    Most compilers have settings to make them warn you about this type of error, since it can be detected at compile-time fairly easily; GCC and Clang have -Wformat which results in the following warnings:

    test.c:5: warning: format ‘%llu’ expects type ‘long long unsigned int’, but argument 2 has type ‘int’
    test.c:5: warning: format ‘%llu’ expects type ‘long long unsigned int’, but argument 3 has type ‘long unsigned int’
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have problem while using jquery maskedinput with asp.net textbox. I have a check
I have a problem with Map objects, while using Gravity. All messages works ok,
I have a problem using JSON and arrays. Here is my code: while($row =
I have a problem when using printf and wprintf functions together in code. If
I have a problem while converting a string whose value is dd.mm.yyyy to DateTime
I have a problem while pasting my contents (or text) generated by Java code
I have a problem while executing a SSIS script component. To be honest I
I have a problem while scrolling images on tableview. I am getting a Signal
i have a problem while loading a UITableView on UITabBarController, i got this error
I have a problem while publishing on the Market. My application does not use

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.