Question: Note: For all the questions, in addition to the answer and output, please also include the explanations. If only providing the correct output and answer,
Note: For all the questions, in addition to the answer and output, please also include the explanations. If only providing the correct output and answer, half of the grades will be given.
1. int x=6;
x+=x-=x*x;
what is the value of x?
2. int j=0;
while (j<25)
j+=3;
cout << j;
What is the output?
3. int a=1, b=2;
What is the value for expression (a++)+b? How about a+++b?
4. char a ='3';
switch(a)
{
case '3': cout << "3";
case '2': cout << "2"; break;
default: cout <<"1";
}
What is the output?
5. int a=1,b=2;
bool c=1;
if((a>b)||c)
cout<<"true"< else cout<<"false"< What is the output? 6. for(int a=0, b=1; b&&a<5; a++) cout <<"*"; How many * will be printed out? 7. int x, y = 0; for (x = 1; x <= 10; x++) { if (y >= 10) break; y = y + x;} cout << y < What is the output? If we change break to continue, what is the output? 8. The function func is defined below. void func(int a, int &b) { a++; b++; } What are the values of x and y respectively if we run the following codes? int x=0, y=1; func(x,y); 9. Read the following program, and figure out its output. #include #include using namespace std; void func(const char* s, char& c) { c = s[strlen(s) / 2]; } int main() { char str[] = "ABCDE"; char ch = str[1]; func(str, ch); cout << ch << endl; return 0; } 10. Read the following loops, and figure out the infinite loops. (1) int i=10; while(1) { i--; if(i==1) break; } (2) for(int i=1; i<10; i++) { i--; } (3) int i=0; do { i++;} while (i>=0); (4) int i=1; for(;;) i=i+1;
Step by Step Solution
There are 3 Steps involved in it
Get step-by-step solutions from verified subject matter experts
