C ++ basic learning notes (4) --- cyclic control structure (test questions)

Source: Internet
Author: User

I. multiple choice questions

1. If the given conditional expression (M )? (A ++) :( a --), where the expression M (C ).

(A) and (M = 0) are equivalent to (B) and (M = 1 ).

(C) and (M! = 0) equivalent (D) and (M! = 1) equivalent

2. in C/C +, the condition for ending the while statement loop is ().

(A) 0 (B) 1 (C) true (D) Non-0

In C/C ++, the condition for ending the do-while statement loop is ().

(A) 0 (B) 1 (C) true (D) Non-0

3. If k is an integer, execute the statement (B) In the while LOOP body below ).

K = 2;

While (k = 0)

{

Printf ("% d", k );

K --; printf ("");

}

(A) unlimited times (B) 0 times (C) 1 time (D) 2 times

4. In the following statement segment, the program segment that is not an infinite loop is (D ). C

(A) I = 100; (B) (;;);

While (1)

{

I = I % 100; I ++;

If (I> 100) break;

}

(C) k = 32764; (D) s = 32764;

Do {while (s ++ % 2) | (s % 2) s ++;

K ++;

} While (k> 0 );

5. In C language, the three basic structures used for structural programming are ().

(A) sequential structure, selection structure, and cyclic structure (B) if, switch, and break

(C) for, while, do-while (D) if, for, continue

6. For the following program section

Int t = 0;

While (t = l)

{...}

Which of the following statements is true? (B ).

(A) The value of the loop control expression is 0 (B). The value of the loop control expression is 1.

(C) invalid loop control expression (D) None of the above statements

 

7. Among the following options, the endless loop is (B ).

(A) int I = 100; (B) for (;); (C) int k = 10000; (D) int s = 36;

While (1) do {k ++;} while (k> 10000); while (s) -- s;

{

I = I % 100 + 1;

If (I = 100) break;

}

8. The following four statement segments correctly indicate the following function relationships: ().

-1 (x <0)

Y = 0 (x = 0)

1 (x> 0)

(A) if (x! = 0) (B) y = 0; (C) if (x <0) y =-l; (D) y =-1;

If (x> 0) y = l; if (x> = 0) if (x! = 0) y = 1; if (x! = 0)

Else y =-l; if (x) y = l; else y = 0; if (x> 0) y = l;

Else y = 0; else y =-l; else y = 0;

Ii. Read the running results of the program analysis program

9. Set int a = 5, B = 6, and the expression (++ a = B --)? + A: The value of -- B is 7.

10. The output of the following program is (B ).

# Include <stdio. h>

Void main ()

{

Int I, j, x = 0;

For (I = 0; I <2; I ++)

{

X ++;

For (j = 0; j <= 3; j ++)

{

If (j % 2) continue;

X ++;

}

X ++;

}

Printf ("x = % d", x );

}

(A) x = 4 (B) x = 8 (C) x = 6 (D) x = 12

11. The output of the following program is (B ).

# Include <stdio. h>

Void main ()

{

Int x = 1, y = 0, a = 0, B = 0;

Switch (x)

{

Case 1:

Switch (y)

{

Case 0: a ++; break;

Case 1: B ++; break;

} // There is no break next to it, so continue to execute case 2.

Case 2:

A ++; B ++; break;

Case 3:

A ++; B ++;

}

Printf ("a = % d, B = % d", a, B );

}

(A) a = l, B = 0 (B) a = 2, B = 1 (c) a = 1, B = l (D) a = 2, B = 2

12. The output of the following program is (B)

# Include <iostream. h>

Void main ()

{

Int I, j, k = 0, m = 0;

For (I = 0; I <2; I ++)

{

For (j = 0; j <3; j ++)

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.