473,394 Members | 1,746 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,394 software developers and data experts.

what data type is the result of a caculation on an int and a double?

okay for instance
Expand|Select|Wrap|Line Numbers
  1. int x = 4;
  2. double y = 2;
  3.  
  4. printf("%d", (x / y + 5));
what data type is
(x / y + 5)
??
thanks
Jun 24 '13 #1
3 1388
Banfa
9,065 Expert Mod 8TB
double

In implicit conversions of this type the compiler always converts up to the type that is largest (holds the largest range of values) in order to get the best chance of using a type that can actually hold the answer.
Jun 24 '13 #2
weaknessforcats
9,208 Expert Mod 8TB
The int is converted to double and the result is double.
Jun 24 '13 #3
donbock
2,426 Expert 2GB
Consider line 4: you associate conversion specifier "%d" with expression (x / y + 5). printf does not warn you if a conversion specifier does not match the type of the corresponding argument. You might prefer to introduce an intermediate variable so that it will be easier for you to notice a mistaken conversion specifier. The implicit conversions are well-defined, but you may not find it easy to remember them.

Expand|Select|Wrap|Line Numbers
  1. int x = 4;
  2. double y = 2;
  3. double z;
  4.  
  5. z = x / y + 5;
  6. printf("%d", z);   // wrong
  7. printf("%f", z);   // right
Jun 24 '13 #4

Sign in to post your reply or Sign up for a free account.

Similar topics

2
by: baylor | last post by:
This is probably an easy question but i apparently can't find the right Google key words i am passed a string and the name of the data type i'm hoping that string is (technically, i'm passed a...
6
by: MLH | last post by:
Runtime error 13 - type mismatch. I get the above error when I create a text box control on a form named and I run the following code in a sub on that same form... If DLookup("", "tblUsers",...
3
by: Sathyaish | last post by:
I wanted to practice some Linked List stuff, so I set out to create a linked list. The plan was to create the following: (1) A linked list class in Visual Basic (2) A non-class based linked list...
5
by: BigAl | last post by:
I am using a SQL server database and am using a Check Box on my .aspx screen. What data type should I use when I design my table? I tried bit but When I ran the program and Checked one of the...
1
by: Neo | last post by:
I have a field named "Male" & this is of SQL BIT data type (SQL Server). How can i bind this field to a check box? I noticed that this field can be NULL, 0 or 1. But i'm having trouble binding...
2
by: Neo | last post by:
I put a similar post for CheckBoxes, but i want to use a Radio button & not a CheckBox I have a field named "Male" & this is of SQL BIT data type (SQL Server). How can i bind this field to a...
2
by: safren | last post by:
1. In c++ (or any other language) I'm copying bit by bit to a double variable dob_var. 2. If I copy dob_var to dob_var2 which is also a double I do not lose information. 3. This implies that the...
1
by: tedqn | last post by:
Problem: - Stored procedure input parameters data type specific (SqlDbType.Int, SqlDbType.VarChar,etc). - Form submitted value in TextBox, DropDownList, etc are all string type (I guess). Some...
5
by: WombatDeath | last post by:
Hi, I want my application to audit any data changes (update, insert, delete) made by the users. Rather than have an audit table mirroring each user table, I'd prefer to have a generic structure...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
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...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
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
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
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
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...

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.