Click here to Skip to main content
15,922,166 members
Home / Discussions / C / C++ / MFC
   

C / C++ / MFC

 
GeneralRe: STAR TREK PROJECT Pin
Wes Aday30-Jun-14 12:43
professionalWes Aday30-Jun-14 12:43 
GeneralRe: STAR TREK PROJECT Pin
Richard MacCutchan30-Jun-14 15:51
mveRichard MacCutchan30-Jun-14 15:51 
QuestionUsing a Self Developed Dll in VC++ Pin
Django_Untaken30-Jun-14 2:20
Django_Untaken30-Jun-14 2:20 
AnswerRe: Using a Self Developed Dll in VC++ Pin
Richard MacCutchan30-Jun-14 4:58
mveRichard MacCutchan30-Jun-14 4:58 
AnswerRe: Using a Self Developed Dll in VC++ Pin
Albert Holguin1-Jul-14 9:13
professionalAlbert Holguin1-Jul-14 9:13 
QuestionCross compiling using Eclipse C/C++ CDT Pin
Vijay Rajanna29-Jun-14 16:25
Vijay Rajanna29-Jun-14 16:25 
AnswerRe: Cross compiling using Eclipse C/C++ CDT Pin
CPallini29-Jun-14 21:52
mveCPallini29-Jun-14 21:52 
QuestionWhen to delete a pointer (C++)... Pin
DanielSheets26-Jun-14 5:24
DanielSheets26-Jun-14 5:24 
AnswerRe: When to delete a pointer (C++)... Pin
Chris Losinger26-Jun-14 5:32
professionalChris Losinger26-Jun-14 5:32 
AnswerRe: When to delete a pointer (C++)... Pin
Orjan Westin26-Jun-14 5:47
professionalOrjan Westin26-Jun-14 5:47 
AnswerRe: When to delete a pointer (C++)... Pin
David Crow26-Jun-14 7:21
David Crow26-Jun-14 7:21 
AnswerRe: When to delete a pointer (C++)... Pin
Freak3027-Jun-14 3:31
Freak3027-Jun-14 3:31 
GeneralRe: When to delete a pointer (C++)... Pin
Stefan_Lang30-Jun-14 22:53
Stefan_Lang30-Jun-14 22:53 
GeneralRe: When to delete a pointer (C++)... Pin
Freak301-Jul-14 22:11
Freak301-Jul-14 22:11 
GeneralRe: When to delete a pointer (C++)... Pin
Stefan_Lang1-Jul-14 22:23
Stefan_Lang1-Jul-14 22:23 
GeneralRe: When to delete a pointer (C++)... Pin
Erik Westermann14-Jul-14 3:40
professionalErik Westermann14-Jul-14 3:40 
AnswerRe: When to delete a pointer (C++)... Pin
CPallini27-Jun-14 7:31
mveCPallini27-Jun-14 7:31 
AnswerRe: When to delete a pointer (C++)... Pin
DanielSheets27-Jun-14 7:40
DanielSheets27-Jun-14 7:40 
GeneralRe: When to delete a pointer (C++)... Pin
Derek Tortonian28-Jun-14 8:50
Derek Tortonian28-Jun-14 8:50 
GeneralRe: When to delete a pointer (C++)... Pin
Stefan_Lang30-Jun-14 23:05
Stefan_Lang30-Jun-14 23:05 
GeneralRe: When to delete a pointer (C++)... Pin
Albert Holguin1-Jul-14 9:17
professionalAlbert Holguin1-Jul-14 9:17 
AnswerRe: When to delete a pointer (C++)... Pin
Joe Woodbury1-Jul-14 6:23
professionalJoe Woodbury1-Jul-14 6:23 
AnswerRe: When to delete a pointer (C++)... Pin
Satya Chamakuri8-Aug-14 23:52
Satya Chamakuri8-Aug-14 23:52 
QuestionMessage Removed Pin
25-Jun-14 22:04
_Flaviu25-Jun-14 22:04 
QuestionBeginner- Floating point character conversion character Pin
BeingGokul24-Jun-14 7:17
BeingGokul24-Jun-14 7:17 
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..

C#
#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..

XML
#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.

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.