473,416 Members | 1,548 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,416 software developers and data experts.

(part 23) Han from China answers your C questions

float and integers

c.***********@gmail.com said
consider following code snippet..
________________________
float a=3.0;
int b=1,c=2;
printf("%d %d %d ",a,b,c);
_________________________

above code give output
0 0 0
i can understand first zero as wrong format(%d) given for a,but i
could not get that why b and c are also printing as zero....
I will be making assumptions here about your system that will
infuriate the pedants, but I don't care. Given your X-HTTP-UserAgent
string, it is highly probable that these assumptions are valid.

Whether you have included stdio.h or not, the float argument to
printf() is promoted to a double, since even with a prototype
visible, the float falls into the variable-list part of the
variadic function printf().

On your system, a double has a 64-bit double-precision IEEE-754
floating-point representation, which means the float 3.0 will be
promoted and represented as 0x4008000000000000.

On your little-endian system, the 0x00 bytes will occur first
in memory.

On your system with 16-bit ints, the %d format specifiers will
operate on 0x0000, 0x0000, 0x0000.

To confirm my explanation, change
printf("%d %d %d ",a,b,c);
to
printf("%d %d %d %d",a,b,c);
and your output should be
0 0 0 16392
Yours,
Han from China

Nov 15 '08 #1
2 1507
On Nov 15, 7:46*pm, Borked Pseudo Mailed <nob...@pseudo.borked.net>
wrote:
float and integers

c.lang.mys...@gmail.com said
consider following code snippet..
________________________
float a=3.0;
int b=1,c=2;
printf("%d %d %d ",a,b,c);
_________________________
above code give output
0 0 0
i can understand first zero as wrong format(%d) given for a,but i
could not get that why b and c are also printing as zero....

I will be making assumptions here about your system that will
infuriate the pedants, but I don't care. Given your X-HTTP-UserAgent
string, it is highly probable that these assumptions are valid.

Whether you have included stdio.h or not, the float argument to
printf() is promoted to a double, since even with a prototype
visible, the float falls into the variable-list part of the
variadic function printf().

On your system, a double has a 64-bit double-precision IEEE-754
floating-point representation, which means the float 3.0 will be
promoted and represented as 0x4008000000000000.

On your little-endian system, the 0x00 bytes will occur first
in memory.

On your system with 16-bit ints, the %d format specifiers will
operate on 0x0000, 0x0000, 0x0000.

To confirm my explanation, change
* * printf("%d %d %d ",a,b,c);
to
* * printf("%d %d %d %d",a,b,c);
and your output should be
* * 0 0 0 16392 *

Yours,
Han from China
Yes,it is showing same o/p as you explained...
It is now clear to me....
Nov 15 '08 #2
On Sat, 15 Nov 2008 08:59:27 -0800 (PST), c.***********@gmail.com wrote:
On Nov 15, 7:46*pm, Borked Pseudo Mailed <nob...@pseudo.borked.net>
wrote:
>to
* * printf("%d %d %d %d",a,b,c);
and your output should be
* * 0 0 0 16392 *

Yours,
Han from China

Yes,it is showing same o/p as you explained...
It is now clear to me....
If this is shorthand for output, it is ambiguous. Lately I write -o x.exe.
Before that I wrote -o out.

OP is the original poster.

An unskillful negating of quoting ettiquette is the mark of a troll. If I
were tasked to pluck ten persons out of clc who didn't turn to stone when
asked a practical question, Han would be on my long list. The authors of
unleashed would be on my short list. Ben would be on top, if I didn't have
to recognize a talent I've never read: Lawrence Jones.
--
George

Faith crosses every border and touches every heart in every nation.
George W. Bush

Picture of the Day http://apod.nasa.gov/apod/
Nov 16 '08 #3

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

1
by: Nomen Nescio | last post by:
A new learner's question Flash Gordon wrote: To the OP, please be aware that Flash Gordon has a history of either deliberately misleading and "miss-informing" posters to this newsgroup or...
0
by: Nomen Nescio | last post by:
what is the type for this call? Neo said: Neo, buddy, I've decided to give you a little summary for reference so that you don't have to sift through excess verbiage, cryptic meanderings,...
0
by: Nomen Nescio | last post by:
No format string passed to variable argument list function Adam said: Then Adam laters says: Then Adam later says:
2
by: Chris Dollin | last post by:
Joachim Schmitz wrote: I think that remark is an ill-considered and unhelpful generalisation. -- "We dance, and the worlds melt away." - Curved Air, /Metamorphosis/ ...
1
by: George Orwell | last post by:
its urgent.pls help me. mona said: mona said: Hey again, mona. Please check the thread "(part 21) Han from China answers your C questions", in which I gave you a program with
0
by: George Orwell | last post by:
fread breaks file descriptors opened in "w" mode. ... Yes, once you break out of ANSI/ISO C, all things are possible. You have posted an on-topic question to comp.lang.c. See version 2.0 of...
16
by: Borked Pseudo Mailed | last post by:
Error handling in C Nick Keighley said: ... ... To the OP, please be aware that Nick Keighley is a known troll and is deliberately providing you with unsound advice. You asked for error...
2
by: Nomen Nescio | last post by:
What is this? Eric said: That looks like either someone's poor coding or someone's poor pasting for an implementation of offsetof() from stddef.h. The (char *) leads me to think that there's...
1
by: George Orwell | last post by:
File Seeking / Overwriting bytes Martien Verbruggen said: And this is, of course, also not right. fseek() does support SEEK_END on text streams. If you want to know why, please start a...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
0
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.