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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 15, 20262026-06-15T00:09:02+00:00 2026-06-15T00:09:02+00:00

Possible Duplicate: What is printf’s behaviour when printing an int as float? int main()

  • 0

Possible Duplicate:
What is printf’s behaviour when printing an int as float?

int main()
{
 int x=4;
 int y=987634;
 printf("%f %f",x,y);
}

On compiling this code i get an output as 0.000000 0.000000. Shouldn’t there be a type promotion of x and y to floating point numbers? Shouldn’t the O/P be 4.000000 and 987634.000000?
Can anyone help me with this. Thanx in Advance.

  • 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-15T00:09:04+00:00Added an answer on June 15, 2026 at 12:09 am

    Conversions happen to arguments to functions with a prototype which includes the specific parameters. The prototype for printf() does not include the specific parameters after the first one

    int printf(const char *format, ...);
    

    so, no arguments after the 1st one get automatically converted except as defined by “default argument conversions” (basically any integer type with a rank lower than int to int and any floating-point type with a rank lower than double to double (thank you, Pascal Cuoq)). You need to convert them explicitly yourself with a cast operation

        printf("%f %f\n", (double)x, (double)y);
    

    Ohhh … and you really, really, really should include the header that has the prototype in question (under penalty of Undefined Behaviour)

    #include <stdio.h>
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Possible Duplicate: Is this undefined C behaviour? #include<stdio.h> int main() { int a=5; printf(%d
Possible Duplicate: strange output in comparision of float with float literal #include<stdio.h> int main()
Possible Duplicate: Why does printf print wrong values? #include<stdio.h> int main(int argc, const char
Possible Duplicate: Segmentation Fault - C #include<stdio.h> #include<string.h> int main() { char *p; printf(enter
Possible Duplicate: C++: What is the printf() format spec for “float”? I am new
Possible Duplicate: Undefined Behavior and Sequence Points the output of the programme #include<stdio.h> main()
Possible Duplicate: Working of fork() in linux gcc Why does this code print two
Possible Duplicate: Weird java behavior with casts to primitive types Why does this code
Possible Duplicate: Strange floating-point behaviour in a Java program I came across this weird
Possible Duplicate: Question about pointers and strings in C #include<stdio.h> int main() { char

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.