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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 26, 20262026-05-26T16:39:07+00:00 2026-05-26T16:39:07+00:00

I executed the following code #include <stdio.h> int main() { printf(%f\n, 9/5); } Output

  • 0

I executed the following code

#include <stdio.h>

int main()
{
    printf("%f\n", 9/5);
}

Output : 0.000000

why not 1 ?

if i write printf("%f %f %d %d\n", (float)9/5, 4, sizeof(float), sizeof(int));

then output is 1.800000 0.000000 4 59

why not 1.800000 4 4 4

on my machine the sizeof (float) is 4

Thanks 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-05-26T16:39:08+00:00Added an answer on May 26, 2026 at 4:39 pm

    This is because your printf format specifier doesn’t match what you passed it:

    9/5 is of type int. But printf expects a float.

    So you need to either cast it to a float or make either literal a float:

    printf("%f\n", (float)9/5);
    printf("%f\n", 9./5);
    

    As for why you’re getting 0.0, it’s because the printf() is reading the binary representation of 1 (an integer) and printing it as a float. Which happens to be a small denormalized value that is very close to 0.0.

    EDIT : There’s also something going with type-promotion on varargs.

    In vararg functions, float is promoted to double. So printf() in this case actually expects a 64-bit parameter holding a double. But you only passed it a 32-bit operand so it’s actually reading an extra 32-bits from the stack (which happens to be zero in this case) – even more undefined behavior.

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

Sidebar

Related Questions

How exactly does fork() work? The following code #include <stdio.h> int main (int argc,
Consider the following code: #include <stdio.h> int main (void) { char str1[128], str2[128], str3[128];
I have the following code: #include <stdio.h> main(int argc, char *argv[]) { int n,st;
Say I have the following c program: #include <stdio.h> int main() { printf(Hello world
everybody out there i write a very simple c code which is following: #include<stdio.h>
The following code: #include <stdio.h> typedef union { int n; char *s; } val_t;
Assuming A.sql contains the following code, then second Select query won’t be executed due
I have issues with the following code: #include <stdio.h> #include <stdlib.h> #include <string.h> #include
#include <stdio.h> #define MAXLENGTH 77 int getline(char[], int); main() { char in_line[MAXLENGTH]; int count,
I have the following code draft. #include <fcntl.h> #include <stdio.h> #include <unistd.h> #include <stdlib.h>

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.