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 652905
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 13, 20262026-05-13T22:19:25+00:00 2026-05-13T22:19:25+00:00

I wrote this tiny code: #include <stdio.h> int main() { size_t temp; temp =

  • 0

I wrote this tiny code:

#include <stdio.h>
int main() {
    size_t temp;
    temp = 100;

    printf("lld=%lld, ld=%ld, u=%u\n", temp, temp, temp);

    return 0;
}

I am running this on a i386 GNU/Linux machine with gcc version 4.1.1 20070105 (Red Hat 4.1.1-52). This is the output that I got:

lld=429496729700, ld=100, u=7993461

I can understand that the first (lld) was printed as garbage because the printf tries to print 8 bytes (for signed long long as signified by lld) when only 4 bytes are available from variable temp.
But, I fail to understand why the last identifier, u is getting printed as garbage – whereas, in my understanding this is the closest applicable identifier for size_t.

Here I have assumed that size_t is unsigned int (which is signed 4 bytes for my i386).

Now, I did a little tweaking with the printf line:

...
printf("ld=%ld, u=%u, lld=%lld\n", temp, temp, temp);
...

and I have a perfectly fine answer (except the lld part).

ld=100, u=100, lld=34331653576851556

Can someone please help me in understanding what exactly am I missing here?

Thanks a lot for any help!

[side note: I tried switching optimization using gcc -O[0,2] tag on/off without any difference in the observation.]

  • 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-13T22:19:26+00:00Added an answer on May 13, 2026 at 10:19 pm

    That’s because what you’ve pushed on the stack is three 32-bit values and your format string tries to use four of them or, more accurately, one 64-bit value and two 32-bit values.

    In the first case, the lld sucks up two 32-bit values, the ld sucks up the third one and the u gets whatever happens to be on the stack after that, which could really be anything.

    When you change the order of the format specifiers in the string, it works differently because the ld sucks up the first 32-bit value, the u sucks up the second and the lld sucks up the third plus whatever happens to be on the stack after that. That’s why you’re getting different values, it’s a data alignment/availability issue.

    You can see this in action with the first value. 429496729700 is equal to (4294967296 + 1) * 100, i.e., (232+1)*100. Your code snippet

    printf("lld=%lld, ld=%ld, u=%u\n", temp, temp, temp);
    

    actually has the following effect:

    What you pass     Stack     What printf() uses
    -------------     -----     ------------------
                     +-----+
    100              | 100 | \
                     +-----+  = 64-bit value for %lld.
    100              | 100 | /
                     +-----+
    100              | 100 |    32-bit value for %ld.
                     +-----+
                     | ?   |    32-bit value for %u (could be anything).
                     +-----+
    

    In the second case

    printf("ld=%ld, u=%u, lld=%lld\n", temp, temp, temp);
    

    the following occurs:

    What you pass     Stack     What printf() uses
    -------------     -----     ------------------
                     +-----+
    100              | 100 |    32-bit value for %ld.
                     +-----+
    100              | 100 |    32-bit value for %u.
                     +-----+
    100              | 100 | \
                     +-----+  = 64-bit value for %lld (could be anything).
                     | ?   | /
                     +-----+
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Ask A Question

Stats

  • Questions 441k
  • Answers 441k
  • Best Answers 0
  • User 1
  • Popular
  • Answers
  • Editorial Team

    How to approach applying for a job at a company ...

    • 7 Answers
  • Editorial Team

    What is a programmer’s life like?

    • 5 Answers
  • Editorial Team

    How to handle personal stress caused by utterly incompetent and ...

    • 5 Answers
  • Editorial Team
    Editorial Team added an answer When you say PKZip, does that mean you actually have… May 15, 2026 at 5:30 pm
  • Editorial Team
    Editorial Team added an answer Well, short answer is that it doesn't work like that… May 15, 2026 at 5:29 pm
  • Editorial Team
    Editorial Team added an answer To see how to do this declaratively (i.e. without a… May 15, 2026 at 5:29 pm

Trending Tags

analytics british company computer developers django employee employer english facebook french google interview javascript language life php programmer programs salary

Top Members

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.