Click here to Skip to main content
15,890,717 members
Home / Discussions / C / C++ / MFC
   

C / C++ / MFC

 
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.
AnswerRe: Beginner- Floating point character conversion character Pin
CPallini24-Jun-14 9:06
mveCPallini24-Jun-14 9:06 
AnswerRe: Beginner- Floating point character conversion character Pin
David Crow24-Jun-14 10:19
David Crow24-Jun-14 10:19 
AnswerRe: Beginner- Floating point character conversion character Pin
M.FarrukhFaizy27-Jun-14 8:45
M.FarrukhFaizy27-Jun-14 8:45 
AnswerRe: Beginner- Floating point character conversion character Pin
Satya Chamakuri9-Aug-14 1:46
Satya Chamakuri9-Aug-14 1:46 
QuestionGraphics Pipeline questions Ortho projection Pin
shiftwik23-Jun-14 12:04
shiftwik23-Jun-14 12:04 
QuestionTwo ChlidFrames in MDI application? Pin
Member 1074879523-Jun-14 8:59
Member 1074879523-Jun-14 8:59 
AnswerRe: Two ChlidFrames in MDI application? Pin
shiftwik23-Jun-14 12:08
shiftwik23-Jun-14 12:08 
Questionhow to get rid of this error *** fatal error C1083: Cannot open include file: 'iostream.h': No such file or directory ***** Pin
Member 1089437823-Jun-14 2:08
Member 1089437823-Jun-14 2:08 
AnswerRe: how to get rid of this error *** fatal error C1083: Cannot open include file: 'iostream.h': No such file or directory ***** Pin
leon de boer23-Jun-14 2:16
leon de boer23-Jun-14 2:16 
AnswerRe: how to get rid of this error *** fatal error C1083: Cannot open include file: 'iostream.h': No such file or directory ***** Pin
«_Superman_»23-Jun-14 2:36
professional«_Superman_»23-Jun-14 2:36 
GeneralRe: how to get rid of this error *** fatal error C1083: Cannot open include file: 'iostream.h': No such file or directory ***** Pin
Member 1089437823-Jun-14 2:47
Member 1089437823-Jun-14 2:47 
GeneralRe: how to get rid of this error *** fatal error C1083: Cannot open include file: 'iostream.h': No such file or directory ***** Pin
leon de boer29-Jun-14 17:23
leon de boer29-Jun-14 17:23 
QuestionRe: how to get rid of this error *** fatal error C1083: Cannot open include file: 'iostream.h': No such file or directory ***** Pin
David Crow23-Jun-14 6:01
David Crow23-Jun-14 6:01 
AnswerRe: how to get rid of this error *** fatal error C1083: Cannot open include file: 'iostream.h': No such file or directory ***** Pin
Member 109213042-Jul-14 22:03
Member 109213042-Jul-14 22:03 
QuestionMFC small help please Pin
dan6060622-Jun-14 20:27
dan6060622-Jun-14 20:27 
AnswerRe: MFC small help please Pin
«_Superman_»22-Jun-14 20:48
professional«_Superman_»22-Jun-14 20:48 
GeneralRe: MFC small help please Pin
dan6060622-Jun-14 22:32
dan6060622-Jun-14 22:32 

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.