What range of values can integer types store in C

0 votes
On a 32-bit machine, can an unsigned long int carry a ten-digit value (1,000,000,000 - 9,999,999,999)?

What are the unsigned long int, long int, unsigned int, short int, short unsigned int, and int ranges?
Jun 21 in C++ by Nicholas
• 2,520 points
10 views

1 answer to this question.

0 votes
You may rely on the following minimal ranges:

-32,767 to 32,767 unsigned short int and int: 0 to 65,535 long int: 0 to 65,535

unsigned long int: 0 to 4,294,967,295 -2,147,483,647 to 2,147,483,647

This means that long int cannot be used to hold any ten-digit value.

However, in C99 and C++11, a bigger type long long int was added (this type is also often supported as an extension by compilers built for older standards that did not include it).

If your compiler supports it, the minimal range for this type is:

long long int: -9,223,372,036,854,775,807 to 9,223,372,036,854,775,807 unsigned long long int: 0 to 18,446,744,073,709,551,615 long long int: 0 to 18,446,744,073,709,551,615

So that kind will suffice (again, assuming you have it).
answered Jun 21 by Damon
• 4,240 points

Related Questions In C++

0 votes
0 answers

Use of min and max functions in C++

Are std::min and std::max better than fmin ...READ MORE

Jun 2 in C++ by Nicholas
• 2,520 points
21 views
0 votes
1 answer

Use of min and max functions in C++

The functions fmin and fmax are designed ...READ MORE

answered Jun 21 in C++ by Damon
• 4,240 points
15 views
0 votes
1 answer

In C++, what is a virtual base class?

When employing multiple inheritance, virtual base classes are used to prevent several "instances" of a particular class from appearing in an inheritance hierarchy. Consider the following example: class A { public: void Foo() {} ...READ MORE

answered Jun 10 in C++ by Damon
• 4,240 points
11 views
0 votes
1 answer

What is the best way to use a HashMap in C++?

The ordered and unordered map containers (std::map and std::unordered map) are included in the standard library.  The items in an ordered map are sorted by key, and insert and access are in O (log n).  For ordered maps, the standard library often use red black trees.  However, this is only an implementation detail.  Insert and access are in O in an unordered map (1).  It is simply another term for a hashtable. An illustration using (ordered) std::map: #include <map> #include <iostream> #include <cassert> int main(int argc, char ...READ MORE

answered Jun 10 in C++ by Damon
• 4,240 points
21 views
0 votes
1 answer

Easiest way to convert int to string in C++

The C++11 version has introduced the std::stoi ...READ MORE

answered Feb 10 in Others by Rahul
• 8,980 points
28 views
0 votes
1 answer

Easiest way to convert int to string in C++

C++ adds std::stoi (and variants for each numeric type) and std::to string, which are the C equivalents of atoi and itoa but expressed in terms of std::string #include <string> std::string s = std::to_string(42); Is therefore ...READ MORE

answered Jun 1 in C++ by Damon
• 4,240 points
25 views
0 votes
1 answer

casting int to char using C++ style casting [duplicate]

Even though the precision is lost, yo ...READ MORE

answered Jun 13 in C++ by Damon
• 4,240 points
9 views
0 votes
1 answer

Easiest way to convert int to string in C++

std::stoi (and variations for each numeric type) ...READ MORE

answered Jun 15 in C++ by Damon
• 4,240 points
14 views
0 votes
1 answer

What data structure is inside std::map in C++?

An associative container is std::map. The standard's ...READ MORE

answered May 31 in C++ by Damon
• 4,240 points
21 views
0 votes
1 answer

Cases of static and dynamic binding in C++

When an object's static type is used to associate it with a member function, this is known as static binding (understand the type of its class). When a pointer or reference is associated with a member function based on the dynamic type of the object, this is known as dynamic binding (understand the instance of the variable at runtime). Before continuing, keep in mind that dynamic binding only works with pointers, references, and virtual functions for the base class. Because everything needed to call the function is known at compile time, the first call is a static binding (also known as early binding). Derived1 d1(1, 10); d1.display_data(); You already know that the d1 instance is a Derived1 automatic variable, and that it will call the Derived1::display data method (). The first condition is incorrect: d1 is neither a pointer nor a reference. The second condition isn't acceptable:  There is no virtual Derived1::display data. The second call is for ...READ MORE

answered Jun 7 in C++ by Damon
• 4,240 points
14 views
webinar REGISTER FOR FREE WEBINAR X
Send OTP
REGISTER NOW
webinar_success Thank you for registering Join Edureka Meetup community for 100+ Free Webinars each month JOIN MEETUP GROUP