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...
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...
Answer True or False for all questions: 1. A society that relies on a market-based economy...
Answer True or False for all questions: 1. A society that relies on a market-based economy will always protect the natural environment. 2. With the technological developments in the twenty-first century, productivity growth is no longer an important factor in economic well-being. 3. The minimum wage is an example of a government price ceiling and results in a reduction in unemployment. 4. Efficient production can be carried out anywhere on or beyond the production possibilities frontier. 5. An economist would...
True/ False Questions: For the following questions, first write whether they are true or false then...
True/ False Questions: For the following questions, first write whether they are true or false then write in a few sentences why it’s true or false. (1.5) a. The processes for producing penicillin and blue cheese both use the Penicillium fungus.     b. The reproductive organs of Amanita muscaria are popular pizza toppings.     c. The fungus Claviceps purpurea is thought to have triggered the infamous Salem witch trials.     d. Saccharomyces cerevisiae is a common household bread mold.    ...
The following three true/false questions pertain to bond risk: Question 1/4 - Bond Risk: True or...
The following three true/false questions pertain to bond risk: Question 1/4 - Bond Risk: True or False: Higher risk bonds will receive a lower rating by bond-rating agencies. 2. True or False: Investors will expect higher returns on higher-risk bonds than on lower-risk bonds. 3. True or False: All else equal, the longer a bond’s term, the higher the bond’s risk. 4. True or False: Generally, loans investors make to the United States government (through Treasury Bills and Treasury Notes)...
1)True or False: Ambiguity is a type of vagueness True False 2)True or False: When determining...
1)True or False: Ambiguity is a type of vagueness True False 2)True or False: When determining whether a report of an argument should be treated as an argument, it is important to consider the context in which the report is made. True True False 3) True or False: In a V argument with two premises, if one of the premises is false, then the argument is definitely weak True False 4) True or False: A report of an argument can...
(True or False) The following is an infinite loop. int main() { bool flag = false;...
(True or False) The following is an infinite loop. int main() { bool flag = false; int num = 0; while(!flag); { cin >> num; if(num == -1) { flag = true; } } return 0; }
True or False Questions: Please answer true or false. 1. Even when care is free at...
True or False Questions: Please answer true or false. 1. Even when care is free at the point of service, we would expect low and high-income individuals with the same level of need to demand different quantities of health care. 2. We would expect the demand curve for physician visits to be more price elastic than the demand curve for inpatient hospital care. 3. A decision by the provincial governments to include counseling by psychologists within the public insurance plan...
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT