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

How to create a variable that can store whole numbers only ? is int numItems = 0; c

Which of the following creates a variable that can store whole numbers only? a. int numItems=0; b. int numItems='0'; c. int numItems="0"; or d. interger numItems=0;
Sep 22 '10 #1
3 3841
If you use a real number to initialize an int variable, the real what happens to the real before it is stored in the variable.
Sep 22 '10 #2
weaknessforcats
9,208 Expert Mod 8TB
This looks like some sort of exam question.

The answer depends on what you call a whole number. The mathematical whole number can be stored in various ways.

For example, a 3 could be stored in an int. But a .3 could also be stored in an int as a 3. In the second case, the programmer has "scaled" the value so that a decimal appears as a whole number.

Your example code uses 0, '0', "0" etc as values. Are these whole numbers in your definition?
Sep 22 '10 #3
donbock
2,426 Expert 2GB
Two of these should generate compiler errors. They can be eliminated.
Sep 23 '10 #4

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

Similar topics

2
by: Jack Higgs | last post by:
I'm building a maths program for year 6 children. Problem with division - I generate a random number between say 1 and 1000. I want to generate another random number which when divided by the...
4
by: Mark | last post by:
Hi all, I have a query which returns 56 results every time. 1 field of the query contains the results of an expression where 55 will contain decimal points and 1 will be a whole number. Is there a...
3
by: Neils Christoffersen | last post by:
Hey all, I wrote on Friday asking for some help moving a common subclass field up to the base class (original post and followup included below). This entails storing whole numbers inside float...
3
by: Nick Weekes | last post by:
Im trying to create a variable that can store all possible simple C# types. This is so I can assign the type to a database column, regardless of whether its string, int, bool etc. But, Id rather...
0
by: SampathTangudu | last post by:
Hi, We are trying to use the Hash Tables for passing information from one aspx page to another aspx page. We are using the below code. IsolatedStorageFile isoStore =...
4
by: Will | last post by:
Hey guys Quick question: how do i find out if the remainder of 4 divided by 2 is a whole number ? NEED CODE PLEAS THANX IN ADVANCE
3
by: moumita | last post by:
I want to create a form and display multiple symbols on it.The problem is how do I create and store the symbols so that I can display one single symbol multiple number of times on the form without...
7
by: alexLIGO | last post by:
Hi, is it possible in python (with/without matplotlib, numpy etc) to store a whole class with its data into a file, instead it to reconstruct every time again? So is there an analogous to the...
5
by: Randeh | last post by:
Simple bubbling sort algorithm, nothing fancy, just trying to find a way to validate each number value as it's entered without creating several arrays and loops using isdigit(). I need to validate...
1
by: ganeshshegde | last post by:
Hi.. Can we store whole file in database? ie it should store in database in same format. .pdf should store in .pdf fomat and .doc should store in .doc fomat.
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
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?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
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
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
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...

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.