Once in a while C++ programmer encounter “intelligence tests” which have the programmer examine some source code and make corrections or modifications to it. Here are a few challenges for you to try.
The code below is to write a dash “-” to the screen 40 times. You can replace, remove, or add one character in the code. Can you find 2 solutions?
```
int j, k = 40;
for( j = 0; j < k; --j)
cout << “-“;
```
```
There are two solutions to this puzzle. First, change the - - j to - - k
int j, k = 40;
for( j = 0; j < k; --k)
cout << "-";
The second solution is to add a negative sign to the j in the comparison statement
int j, k = 40;
for( j = 0; -j < k; --j)
cout << "-";
```
You might also like to view...
Write a recursive definition of a valid Java identifier.
What will be an ideal response?
From the list below, which is a valid variable name?
A. jump_over B. _jumpover C. jumpOver_ D. All are valid.
JRadioButtons are useful when you want to give the user the ability to select more than one of the presented options.
Answer the following statement true (T) or false (F)
You recently completed a network overhaul over the weekend. Everything seems to be functioning properly until you receive a swarm of help desk support requests, all originating from one specific floor in your building. After a few minutes on the phone with those affected, you determine that no one has indicator lights active on their NICs. What is the most likely problem?
A. The DHCP server has failed. B. A gateway is incorrectly configured. C. Static IP address settings have prevented the NIC from entering a usable state. D. A network switch is powered off.