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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 3, 20262026-06-03T03:18:10+00:00 2026-06-03T03:18:10+00:00

For the following code: #include <stdio.h> int main(){ printf(%f, 5); printf(%d, 5.01); } The

  • 0

For the following code:

#include <stdio.h>
int main(){
    printf("%f", 5);
    printf("%d", 5.01);
}

The first statement will print 0.000000 and the second statement will print a large number.

I thought the printf see the format %f will pop a 4-byte argument from stack. Then I looked up some references that say the printf function will transform float into double, so 8-byte argument. So I thought it may print out a unpredictable value. But how could it print out a 0.000000.

The second one is also weired. The binary format for 5.01 should be 0 10000001 01000000101000111101100 (0x40A051EC), It should be 1084248556 in decimal format, but the result of the statement is 1889785610. Why is this happen?

  • 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-03T03:18:12+00:00Added an answer on June 3, 2026 at 3:18 am

    This is confusing, but %d is the format for an integer, like %i (most people expect it to be for double since %f is for float, but it’s not). You can’t use it with a double, you must use %f. Same with %f, you can’t use an integer with it; you must use a float or double.

    Also, printf doesn’t check the types you use it with, it just blindly interprets bytes as the types you tell it you gave it. Using the wrong types with the wrong type specifiers yields undefined behaviour which is why you’re seeing what you are.

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

Sidebar

Related Questions

This code #include <stdio.h> #include <stdlib.h> #include <time.h> int main () { printf (First
I executed the following code #include <stdio.h> int main() { printf(%f\n, 9/5); } Output
Consider the following code: #include <stdio.h> int main() { printf(%d, 300 * 300 /
i have the following code: #include <stdio.h> int main(void) { float a[4] __attribute__((aligned(0x1000))) =
The following code outputs Illegal seek: #include <stdio.h> #include <errno.h> #include <string.h> int main()
Consider the following code which shows compile time error : #include <stdio.h> int main(int
Consider the following code: #include <stdio.h> int main (void) { char str1[128], str2[128], str3[128];
How exactly does fork() work? The following code #include <stdio.h> int main (int argc,
I have a problem with the following code: #include <stdio.h> #include <iostream> int main
The following code works fine #define open { #define close } #include<stdio.h> #define int

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.