Chapter 5 Quiz Starting Out With C++ 021

Can you omit or leave out the initialization expression from a for-loop?

int i= 1;
int maxVal=10;

for ( ; i<= maxVal; i++)
   cout << i << "\t\t" << (i * i) << "\n";

a. yes, if you have already initialized the test variable
b. yes, the for loop will automatically create the variable i and set it to 0
c. no, the compiler will generate an error
d. no, the program will run and then give a syntax error once you hit the loop

1 comment:

  1. a. yes, if you have already initialized the test variable

    ReplyDelete