Yahoo Answers is shutting down on May 4th, 2021 (Eastern Time) and beginning April 20th, 2021 (Eastern Time) the Yahoo Answers website will be in read-only mode. There will be no changes to other Yahoo properties or services, or your Yahoo account. You can find more information about the Yahoo Answers shutdown and how to download your data on this help page.

C++ question regarding numbers?

how do I properly use these objects? Give me a definition.

int

float

double

long

short

long long

Update:

Thanks for the info Michael, also gave me helpful tips I didn't know I needed!

2 Answers

Relevance
  • 9 years ago
    Favorite Answer

    Those are all fundamental data types of the language, not objects.

    int, short, long and long long are integer types capable of holding signed integers of implementation defined (subject to he constraints imposed by the language definition) sizes.

    The exact range of values that can be held in variables of these types is defined in the <limits.h> header file.

    Similarly, float and double are floating point data types.

    Generally speaking you should use "int" for integer types unless you have a specific reason not to.

    For example, if you know that the data that your dealing with will always fit in 16 bits and you need to store a lot of it you might choose to use "short" to save space. You might also consider including <stdint.h> and using types such as int16_t or int64_t if you know the exact size that you want.

    Get in the habit of using typedefs such as offset_t for file offsets and ptrdiff_t for the difference between two pointers.

    Avoid unsigned types unless you really need them and beware of the potential for unexpected results when mixing signed and unsigned types in arithmetic expressions - some of the rules for type and value conversion in such expressions are not intuitively obvious and need to be learned.

    For floating point values you will almost always want to use "double" unless you are really concerned about space and not concerned about accuracy in which case "float" might be appropriate.

  • 4 years ago

    include79abd8cf35895c56cc4d955c5355dbe utilising namespace std; #incorporate cmath #incorporate iostream utilising namespace std; int sum_primes(int N) {/*interior function you have been returned taking fee which isn't fabulous cout << "enter a variety:t "; cin >> N;*/ int i, count variety = 0, sum = 0, x; bool top; for(x = 2; x <= N; x++) { top = authentic; for(i = 2; i <= sqrt(x); i++) { if (x % i == 0) { top = fake; count variety++; } } if (top) sum += x; } if (count variety == 0 && N>3)/* earlier right here it grow to be N!=a million*/ sum += N; return sum; } int significant(){ int Q; cout << "enter a variety:t "; cin >> Q; cout << "The sum of those primes is: " << sum_primes(Q); return 0; }

Still have questions? Get your answers by asking now.