Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
CODE PROJECT For Those Who Code
  • Home
  • Articles
  • FAQ
Community
B

BeingGokul

@BeingGokul
About
Posts
1
Topics
1
Shares
0
Groups
0
Followers
0
Following
0

Posts

Recent Best Controversial

  • Beginner- Floating point character conversion character
    B BeingGokul

    Hi, I am no expert in C and I have started learning it again after several years. Excuse me for stupid questions. My question is simple. When i give %f as conversion character inside printf, but pass some integer to it, what happens? It prints some garbage value? or is there any pattern? Consider the below program..

    #include <stdio.h>
    main()
    {
    float gift1, gift2;
    float total;
    printf("How much do you want to spend on 1 \n");
    scanf(" %f", &gift1);
    printf("How much do you want to spend on 2 \n");
    scanf(" %f", &gift2);
    total = gift1+gift2;
    printf("\nThe total you will be spending on gifts is $%.2f", total);
    printf("\n %s %d %f %c", "Gokul", 90, 100, 'X');
    return 0;
    }

    In the above program, i have added a final printf which has nothing to do with the rest of the program. I have simply added it. And i have passed the integer 100 to the %f conversion character. While executing the program, i give some random values for gift1,gift2 which accounts to, say 1958.9967. So, total is 1958.9967 But the value of total is also printed as part of my final line, like below Gokul 90 1958.9967 Here, X is not printed as well. So, what is happening. Instead of 100, when i tried with 100.19, it gives the desired result (like below) Gokul 90 100.19 X I tried another small program like below..

    #include<stdio.h>
    main()
    {
    printf("\n %f specifies floating number, but i will give an integer",1987);
    return 0;
    }

    Here, my output was like below 0.000000 specifies floating number, but i will give an integer. Here, where does this 0.000000 comes from? In case of previous program it printed the value of "total" - why? what is the behavior here? Btw, I am using Code Blocks compiler, if that's of any significance here. Thanks in advance.

    C / C++ / MFC question learning regex json lounge
  • Login

  • Don't have an account? Register

  • Login or register to search.
  • First post
    Last post
0
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups