THIS IS ALL IN C++. Using what you’ve learned about declaring integer variables
ID: 3743520 • Letter: T
Question
THIS IS ALL IN C++.
Using what you’ve learned about declaring integer variables and the syntax for integer literals, provide the correct variable types for each of the eight variable declarations in this program. You can assume that ints are 32 bits and that shorts are 16 bits. Use the smallest legal type that will correctly store the subsequent value
#include <iostream>
using namespace std;
#include "declarations.h"
int main()
{
// Complete the following variable declarations
// Using the smallest correct type for each
? a = -25;
? b = 249;
? c = -1725;
? d = 49752;
? e = -2000000252;
? f = 3U;
? g = -9LL;
? h = 25ULL;
check("a", a);
check("b", b);
check("c", c);
check("d", d);
check("e", e);
check("f", f);
check("g", g);
check("h", h);
return 0;
}
Explanation / Answer
// In C++ range of short int will be:- "-32768 to 32767" and int will be "-2147483648 to 2147483647"
// now unsigned short int range will be "0 to 65535" and unsigned int will be "0 to 4294967295"
// variable declarations
short int a = -25;
short int b = 249; // here you can also declare as a unsigned short int
short int c = -1725;
int d = 49752;
int e = -2000000252;
short int f = 3U;
short int = -9LL;
short int h = 25ULL;
Related Questions
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.