By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
435,204 Members | 1,171 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 435,204 IT Pros & Developers. It's quick & easy.

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

P: 2
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
Share this Question
Share on Google+
3 Replies


P: 2
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
Expert Mod 5K+
P: 9,197
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

Expert 100+
P: 2,400
Two of these should generate compiler errors. They can be eliminated.
Sep 23 '10 #4

Post your reply

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