answersLogoWhite

0


Best Answer

In C Programming, the range of integer values that we can reliably represent with an int data type is exactly the same as for a char data type: -127 to +127. While an int is usually capable of covering a much wider range of values than a char, this range is the absolute minimum we can guarantee across all C implementations.

Note that while most (all?) modern systems support twos-complement signed notation to yield a minimum range of -128 to +127, we cannot guarantee this range on a ones-complement system because these systems have two separate representations for the value 0, reducing the range by 1 value. 0 is neither positive nor negative, hence the introduction of twos-complement notation.

If we need to determine the maximum guaranteed range we can represent with a built-in type upon any given implementation, then we must use the implementation-defined constants declared in the C standard library header, :

#include

int minimum = INT_MIN;

int maximum = INT_MAX;

Note that on any given system, we can always make the following assertions in C programming:

assert (8<=CHAR_BIT); // CHAR_BIT is defined in

assert (sizeof(char)==1);

assert (sizeof(short)<=sizeof(char));

assert (sizeof(int)<=sizeof(short));

assert (sizeof(long)<=sizeof(int));

assert (sizeof(long long)<=sizeof(long));

These limitations are defined by the C standard. Note that while a char is always 1 byte in length, the length of a byte (in bits) is implementation-defined but is always at least 8 (bits). Systems with 9-bit or 16-bit bytes are not uncommon, but are catered for by the standard. Older systems that support a 7-bit byte are not catered for by the standard, however non-standard implementations do exist to cater for these specific systems.

User Avatar

Wiki User

7y ago
This answer is:
User Avatar
More answers
User Avatar

Wiki User

8y ago

It depends on the programming language. In C++, all built-in type lengths are implementation defined. However, you can use the implementation itself to determine the limits for any numeric type, like so:

#include<iostream>

#include<limits>

int main() {

std::cout << "Minimum value for int: " << std::numeric_limits<int>::min() << '\n';

std::cout << "Maximum value for int: " << std::numeric_limits<int>::max() << '\n';

}

This answer is:
User Avatar

Add your answer:

Earn +20 pts
Q: What are the largest and smallest values that can be reliably stored in a variable of type int?
Write your answer...
Submit
Still have questions?
magnify glass
imp
Continue Learning about Engineering

How do you find the smallest value in a set of numbers in qbasic?

Store the numbers in a suitable container such as an array. Assume the first number is the smallest and assign its value to a local variable. Traverse the remainder of the sequence, comparing each element's value to the stored value. If an element has a lower value, assign its value to the local variable. When the sequence is fully traversed, the local variable will hold the value of the smallest value in the sequence. Return that value.


What a C function that will compute the K in largest and K in smallest element along with their positions in an array of N signed integers. Assume the following 5 N 50 and 1K?

To compute the largest value in an array, assume that the first element is the largest and store the value. Then traverse the remainder of the array. Each time a larger value is encountered, update the stored value. Once all values are traversed, return the stored value. In pseudocode, this algorithm would be implemented as follows: Algorithm: largest Input: array A of length N Output: largest value in A let largest = A[0] // store first value for index = 1 to N-1 // traverse remaining elements if A[index] &gt; largest then largest = A[index] // update stored value if current value is larger next index return largest To determine the position of the largest value, we alter the algorithm as follows: Algorithm: largest_by_index Input: array A of length N Output: index of the largest value in A let largest = 0; // store index 0 for index = 1 to N-1 // traverse remaining elements if A[index] &gt; A[largest] then largest = index // update stored index next index return largest We can do the same to find the position of the smallest element: Algorithm: smallest_by_index Input: array A of length N Output: index of the smallest value in A let smallest = 0; // store index 0 for index = 1 to N-1 // traverse remaining elements if A[index] &lt; A[smallest] then smallest = index // update stored index next index return smallest To perform both algorithms simultaneously, we need to return two values. To achieve this we can use a simple data structure known as a pair: struct pair { int smallest; int largest; }; Algorithm: range_by_index Input: array A of length N Output: a pair indicating the position of the smallest and largest values in A pair result = {0, 0} // initialise the pair for index = 1 to N-1 // traverse remaining elements if A[index] &lt; A[result.smallest] then result.smallest = index // update stored index else if A[index] &gt; A[result.largest] then result.largest = index // update stored index next index return result


Where the local variables will be stored?

When you declare a variable and it's data type in a function, it is stored in the specific space for memory allocated by the variable type identifier known as the "stack."


Where string is stored on Heap or Stack in java?

A String is treated as an object, meaning there is an object on the heap. Of course, the variable you define is a pointer to the object, and it is stored on the stack.A String is treated as an object, meaning there is an object on the heap. Of course, the variable you define is a pointer to the object, and it is stored on the stack.A String is treated as an object, meaning there is an object on the heap. Of course, the variable you define is a pointer to the object, and it is stored on the stack.A String is treated as an object, meaning there is an object on the heap. Of course, the variable you define is a pointer to the object, and it is stored on the stack.


Where the variables are stored in the computer?

Variable stored in the memory block inside the RAM. whenever we declare a variable it would take space in main memory and consume it's size from RAM.

Related questions

How do you find the smallest value in a set of numbers in qbasic?

Store the numbers in a suitable container such as an array. Assume the first number is the smallest and assign its value to a local variable. Traverse the remainder of the sequence, comparing each element's value to the stored value. If an element has a lower value, assign its value to the local variable. When the sequence is fully traversed, the local variable will hold the value of the smallest value in the sequence. Return that value.


Can elements with variable valency can be stored in water?

Yes elements with variable valency can be stored in water. example Phosphorus.


What a C function that will compute the K in largest and K in smallest element along with their positions in an array of N signed integers. Assume the following 5 N 50 and 1K?

To compute the largest value in an array, assume that the first element is the largest and store the value. Then traverse the remainder of the array. Each time a larger value is encountered, update the stored value. Once all values are traversed, return the stored value. In pseudocode, this algorithm would be implemented as follows: Algorithm: largest Input: array A of length N Output: largest value in A let largest = A[0] // store first value for index = 1 to N-1 // traverse remaining elements if A[index] &gt; largest then largest = A[index] // update stored value if current value is larger next index return largest To determine the position of the largest value, we alter the algorithm as follows: Algorithm: largest_by_index Input: array A of length N Output: index of the largest value in A let largest = 0; // store index 0 for index = 1 to N-1 // traverse remaining elements if A[index] &gt; A[largest] then largest = index // update stored index next index return largest We can do the same to find the position of the smallest element: Algorithm: smallest_by_index Input: array A of length N Output: index of the smallest value in A let smallest = 0; // store index 0 for index = 1 to N-1 // traverse remaining elements if A[index] &lt; A[smallest] then smallest = index // update stored index next index return smallest To perform both algorithms simultaneously, we need to return two values. To achieve this we can use a simple data structure known as a pair: struct pair { int smallest; int largest; }; Algorithm: range_by_index Input: array A of length N Output: a pair indicating the position of the smallest and largest values in A pair result = {0, 0} // initialise the pair for index = 1 to N-1 // traverse remaining elements if A[index] &lt; A[result.smallest] then result.smallest = index // update stored index else if A[index] &gt; A[result.largest] then result.largest = index // update stored index next index return result


What is a function of a variable?

A variable is a named memory address in which a value may be stored and mutated.


Is the smallest unit of data that can be stored?

byte


What is session in aspnet?

session is a server variable. it works like the ordinary variable but it is stored on the server


Where the local variables will be stored?

When you declare a variable and it's data type in a function, it is stored in the specific space for memory allocated by the variable type identifier known as the "stack."


What is the smallest unit of data that can be stored?

A bit is the smallest amount of info a computer can store...


What is the smallest prime number that can be stored in an 8-bit memory?

The smallest prime number is 2.


Where string is stored on Heap or Stack in java?

A String is treated as an object, meaning there is an object on the heap. Of course, the variable you define is a pointer to the object, and it is stored on the stack.A String is treated as an object, meaning there is an object on the heap. Of course, the variable you define is a pointer to the object, and it is stored on the stack.A String is treated as an object, meaning there is an object on the heap. Of course, the variable you define is a pointer to the object, and it is stored on the stack.A String is treated as an object, meaning there is an object on the heap. Of course, the variable you define is a pointer to the object, and it is stored on the stack.


Where is constant variable stored?

Random Access Memory (RAM)


Where the variables are stored in the computer?

Variable stored in the memory block inside the RAM. whenever we declare a variable it would take space in main memory and consume it's size from RAM.