Question

In: Computer Science

C++ Questions: 1. True/False: an int uses 4 bytes in memory on all systems. 2. True/False:...

C++ Questions:

1. True/False: an int uses 4 bytes in memory on all systems.

2. True/False: a double typically offers better precision than a float.

3. True/False: The following two statements are equivalent assuming isPair is a variable of type bool:

if (isPair)
if (isPair == true)

4. Provide a value we could put in the blank so that the value of x will be 20 after the code snippet.

int x = _____;
x *= 4;

5. Provide a value we could put in the blank so that the value of x will be 7 after the code snippet.

int x = _____;
x = x % 10;

6. What is the error in the code below:

string slogan = 'Go Giants!';

Solutions

Expert Solution

Solution:

(1)

The answer will be "False"

Explanation:

=>If processor system is 16 bits then size of int = 2 bytes

=>If processor system is 32 bits then size of int = 4 bytes

=>So on the basis of above statements we can say that int can take 2 byte or 4 byte depending upon the processor system.

(2)

The answer will be "true"

Explanation:

=>Double uses more bits after decimal point as compared to float and it gives more precise computation.

(3)

The answer will be "true"

Explanation:

=>In if(isPair), isPair is a boolean variable if value of isPair = 1 then if condition will be true otherwise false.

=>In if(isPair == 1) isPair boolean variable's value will be compared with 1 if the value of isPair variable is 1 then condition isPair == 1 will return true otherwise false.

=>Hence on the basis of above statements we can say that given both expressions are equivalent.

(4)

The answer will be "5".

Explanation:

=>x *= 4; means x = x*4 so when x = 5 value of x = 5*4 means x = 20.

(5)

The answer will be "7"

Explanation:

=>x = x % 10 where % is modulus operator.

=>When x = 7, x = 7 % 10 will imply x = 7.

(6)

The answer will be "Instead of single quotes there should be double quotes"

Explanation:

=>As slogan is of string type so 'Go Giants!' is not correct because in single quote characters are represented not string so there should be double quotes.

I have explained each and every part with the help of statements attached to it.


Related Solutions

6 C++ Questions: 19. Assuming an int is size 4 bytes, what is the size in...
6 C++ Questions: 19. Assuming an int is size 4 bytes, what is the size in memory of the below array: int cards[10] = {7, 4, 7, 5, 7}; 20. In the array from question 19, what is the value of the below elements: cards[1]; cards[8]; Assume you have an array with 128 integers which is sorted from lowest to highest. 21a. You are searching for a value which is contained in the array using the binary search algorithm. What...
This is a question about C# programming: True / False questions: for (int i=5; i <...
This is a question about C# programming: True / False questions: for (int i=5; i < 55; i+=5) { decimal decPrcPerGal = decGalPrc + i; decPayPrc = iBuyGall * decPrcPerGal; if (decPrcPerGal > decMAX_GALPRC) { continue; } if (decPrcPerGal > decMAX_GALPRC) { break; } Console.WriteLine(" {1} gallon(s) at {0,3} would cost {2,8:$###,##0.00}", decPrcPerGal, iBuyGall, decPayPrc); } In the code above: 1. If decGalPrc is 10.57 decPrcPerGal will always be some number of dollars and 57 cents   True/ False? 2. In...
For a given two-dimensional array in C as follows (Each int-type element occupies 4 bytes of...
For a given two-dimensional array in C as follows (Each int-type element occupies 4 bytes of memory) int A[8][16]; If the address of A[1][4] is 0x0FFA0040, what is the memory address of A[2][6]?
with C# create a console application project that outputs the number of bytes in memory that...
with C# create a console application project that outputs the number of bytes in memory that each of the following number types use, and the minimum and maximum values they can have: sbyte, byte, short, ushort, int, uint, long, ulong, float, double, and decimal. Try formatting the values into a nice-looking table! More Information: You can always read the documentation, available at https://docs.microsoft.com/en-us/dotnet/standard/base-types/composite-formatting for Composite Formatting to learn how to align text in a console application. Your output should look...
True or False Questions: Determine if true or false. If false why? 1) Premature efforts to...
True or False Questions: Determine if true or false. If false why? 1) Premature efforts to treat problem behavior before determining its function can be inefficient, ineffective, and even harmful. 2) Research has found that functional analyses conducted in natural environments (e.g., classroom settings) often yield the same (or even clearer) results compared to those conducted in simulated settings. 3) Problem behavior can only be maintained by one function. Behaviors are not multi-functional. 4) Indirect functional assessment procedures are referred...
True or False for the following questions...... 1) The following reaction is spontaneous at all temperatures....
True or False for the following questions...... 1) The following reaction is spontaneous at all temperatures. 2NO2(g) --> N2(g) + 2O2(g) ∆H = -123 kJ 2) The following reaction is spontaneous at all temperatures. 3O2(g) --> 2O3(g) ∆H = +423 kJ 3) If the following reaction takes place at 300 K, the reaction is spontaneous at 300 K. N2(g)  + 3H2(g) -->   2NH3(g) ∆H = -90 kJ ∆S for N2(g) = 192 J/molK; ∆S for H2(g) = 131 J/molK; ∆S for...
Answer the following questions True or False. Write “True” or “False” in the blank. 1._________ The...
Answer the following questions True or False. Write “True” or “False” in the blank. 1._________ The rate constant changes if the concentrations of the reactant change. 2._________ If the concentration of a reactant changes, the rate of the reaction always changes. 3._________ The coefficients of the overall reaction tell us the order for each reactant. 4._________ The half-life for a first order reaction does not depend on the initial concentration. 5._________ If the rate of a reaction over a long...
1. All mutations are harmful. a) True b) False 2. Which of the following is TRUE...
1. All mutations are harmful. a) True b) False 2. Which of the following is TRUE about mutations? a) Mutations are more likely to occur if they result in a useful trait b) Mutations can be inherited. c) Mutations only occur during DNA replication d) Mutations do not occur in organisms that reproduce asexually 3. Which of the following would increase the chances of getting a mutation? a) Wearing a hat outside b) Putting sunscreen on your face and arms...
C# Create a console application project that outputs the number of bytes in memory that each...
C# Create a console application project that outputs the number of bytes in memory that each of the following number types use, and the minimum and maximum values they can have: sbyte, byte, short, ushort, int, uint, long, ulong, float, double, and decimal. Try formatting the values into a nice-looking table! Your output should look something like this: | Type | Bytes of Memory | Min | Max |
T/F Conceptual Questions and Explanations (2 pts for a true statement, 4 pts for a false...
T/F Conceptual Questions and Explanations (2 pts for a true statement, 4 pts for a false statement). Instructions: A statement is true if it is true in all cases and under all conditions. Otherwise, it is false. If a statement is true, no explanation is needed. If a statement is false, you need to point out the mistakes and come up with a correct statement ______ By definition, reduced costs of all decision variables in a linear program should be...
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT