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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 25, 20262026-05-25T17:53:56+00:00 2026-05-25T17:53:56+00:00

Here is my program: #include <stdio.h> int main() { int a=0x09; int b=0x10; unsigned

  • 0

Here is my program:

#include <stdio.h>
int main()
{
    int a=0x09;
    int b=0x10;
    unsigned long long c=0x123456;
    printf("%x %llx\n",a,b,c);//in "%llx", l is lowercase of 'L', not digit 1
    return 0;
}

the output was:

9 12345600000010

I want to know:

  1. how function printf() is executed?
  2. what will happen if the number of arguments isn’t equal to that of formats?

please help me and use this program as an example to make an explanation.

  • 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-25T17:53:57+00:00Added an answer on May 25, 2026 at 5:53 pm

    The problem is that your types don’t match. This is undefined behavior.

    Your second argument b does not match the type of the format. So what’s happening is that printf() is reading past the 4 bytes holding b (printf is expecting an 8-byte operand, but b is only 4 bytes). Therefore you’re getting junk. The 3rd argument isn’t printed at all since your printf() only has 2 format codes.

    Since the arguments are usually passed consecutively (and adjacent) in memory, the 4 extra bytes that printf() is reading are actually the lower 4 bytes of c.

    So in the end, the second number that’s being printed is equal to b + ((c & 0xffffffff) << 32).

    But I want to reiterate: this behavior is undefined. It’s just that most systems today behave like this.

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

Sidebar

Related Questions

Here is one program #include<stdio.h> #include<stdlib.h> int main() { unsigned char a=0x80; printf(%d\n,a<<1); }
I compile this program: #include <stdio.h> int main() { printf(Hello World!); return 0; }
The following C program: #include <stdio.h> int main(void) { printf("%u %u %u\n",sizeof "",sizeof(""+0),sizeof(char *));
The output of following program #include<stdio.h> int main(){ int *p[10]; printf(%ld %ld\n,sizeof(*p),sizeof(p)); } is
Here is my server program #include<stdio.h> #include<stdlib.h> #include<sys/socket.h> #include<sys/un.h> #include<sys/types.h> #include<unistd.h> int main ()
Consider this little program: #include <stdio.h> int main() { char c = 0xFF; printf(%d\n,
I wrote the following program: #include<stdio.h> int main(void) { float f; printf(\nInput a floating-point
I've the following program: #include <stdio.h> int main() { int ch; while( ch =
I am confused with this program. #include <stdio.h> int main(void) { char* ptr=MET ADSD;
I have a C Program: #include <stdio.h> int main(){ int b = 10; //assign

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.