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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 11, 20262026-06-11T00:55:21+00:00 2026-06-11T00:55:21+00:00

My code is void main() { float a = 0.7; if (a < 0.7)

  • 0

My code is

void main()
{
    float a = 0.7;
    if (a < 0.7)
        printf("c");
    else
        printf("c++");
} 

It prints C and this is fine as a treated as double constant value and its value will be 0.699999 which is less than 0.7.

Now if I change the value to 0.1,0.2,0.3 till 0.9 in a and also at if condition then it prints C++, apart from 0.7 and 0.9 that mean both are equal or a is greater.

Why this concept not consider for all value?

  • 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-11T00:55:23+00:00Added an answer on June 11, 2026 at 12:55 am

    What “concept” are you talking about?

    None of the numbers you mentioned are representable precisely in binary floating-point format (regardless of precision). All of the numbers you mentioned end up having infinite number of binary digits after the dot.

    Since neither float nor double have infinite precision, in float and double formats the implementation will represent these values approximately, most likely by a nearest representable binary floating-point value. These approximate values will be different for float and double. And the approximate float value might end up being greater or smaller than the approximate double value. Hence the result you observe.

    For example in my implementation, the value of 0.7 is represented as

    +6.9999998807907104e-0001 - float
    +6.9999999999999995e-0001 - double
    

    Meanwhile the value of 0.1 is represented as

    +1.0000000149011611e-0001 - float
    +1.0000000000000000e-0001 - double
    

    As you can see, double representation is greater than float representation in the first example, while in the second example it is the other way around. (The above are decimal notations, which are rounded by themselves, but they do have enough precision to illustrate the effect well enough.)

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

Sidebar

Related Questions

Consider this code: void res(int a,int n) { printf(%d %d, ,a,n); } void main(void)
I came across this code: #include<stdio.h> void main() { int x; float t; scanf(%f,&t);
i have the following code: #include <stdio.h> int main(void) { float a[4] __attribute__((aligned(0x1000))) =
I have this code : void Main() { System.Timers.Timer t = new System.Timers.Timer (1000);
this is my C# code: void main() { SystemEvents.SessionEnding += new SessionEndingEventHandler(SystemEvents_SessionEnding); } void
Consider the following code in C: void main() { int a=0; for(printf(\nA); a; printf(\nB));
#include <stdio.h> void main() { extern int fun(float); int a=fun(3.5); printf(%d,a); } int fun(aa)
I have the code : #include<stdio.h> void main(){ int i; float a=5.2; char *ptr;
int main(void) { int x; float y; x=10; y=4.0; printf(%d\n,x/y); return 0; } I
I have some code static void Main(string[] args) { int j = 0; for

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.