quiz02 - Selection, Repetition and Increment / Decrement, Arithmetic Expressions and Operator Precedence

  1. Question: For what exact range of values of variable x does the following code segment display the letter 'C'?
     
     if (x <= 200)
    
     if (x < 100)
    
     if (x <= 0)
    
     printf("A\n");
    
     else
    
     printf("B\n");
    
     else
    
     printf("C\n");
    
     else
    
     printf("D\n");
     
     
    
    Choose the best Answer :
    1. 0 < x < 100
    2. x <= 0
    3. 100 <= x <= 200
    4. x > 200
    5. 100 < x <= 200
  2. Question: If num is a variable of type int and temp is a variable of type double, how could you correctly complete this function call?
    
     scanf("%lf%d", _________);
    
     
    Choose the best Answer :
    1. num, temp
    2. &num, &temp
    3. temp, num
    4. &temp, &num
    5. none of the above
  3. Question: If the value of control is 5, the following switch statement will cause a run-time error.
    
    switch (control) {
    
    	case 1: 
    
    		printf("one");
    
    		break;
    
    	case 2: 
    
    		printf("two");
    
    		break;
    
    	case 3: 
    
    		printf("three");
    
    		break;
    
    	case 4: 
    
    		printf("four");
    
     }
     
     
    Choose the best Answer :
    1. true
    2. false
  4. Question: The following decision statement is coded correctly:
    
     if x <= y
    
    	printf("%f", x);
    
     else
    
    	printf("%f", y);
     
     
    Choose the best Answer :
    1. true
    2. false
  5. Question: The following program segment gives x and y the same value if the condition is true:
    
     if (x > y) {
    
    	 y = x;
    
    	 x = y;
    
     } 
    
     
    Choose the best Answer :
    1. true
    2. false
  6. Question: What does the following if statement display?
    
     if (13 < 12)
    
    	printf("never\n");
    
     else
    
    	printf("always\n");
    
    
     
    Choose the best Answer :
    1. never
    2. always
  7. Question: What is displayed by the C statements that follow if the input value is 2?
    
    scanf("%d", &ctl);
    
    switch (ctl) {
    
     case 0:
    
     case 1:
    
    	printf("red ");
    
     case 2:
    
    	printf("blue ");
    
     case 3:
    
    	printf("green ");
    
     case 4:
    
    	printf("yellow");
    
     }
    
     printf("\n");
    
    
     
    Choose the best Answer :
    1. red
    2. blue
    3. green
    4. yellow
    5. blue green yellow
  8. Question: What is the program output if the user types runt followed by a carriage return when the program is run?
    
    char r, x, y, z, w;
    
     scanf("%c%c%c%c", &x, &y, &z, &w);
    
     if (x < y)
    
    	r = x;
    
     else
    
    	r = y;
    
     if (r > z)
    
    	r = z;
    
     if (r > w)
    
    	r = w;
    
     printf("%c\n", r);
    
    
     
    Choose the best Answer :
    1. r
    2. u
    3. n
    4. t
    5. none of the above
  9. Question: What is displayed by the C statements at the right if the value input is 3?
    
     scanf("%d", &n);
    
     if (n = 5)
    
         { printf("Equal\n"); }
    
     else if (n < 5)
    
         { printf("Less\n"); }
    
     else
    
        { printf("Greater\n"); }
    
    
     
    Choose the best Answer :
    1. Equals
    2. Less
    3. Greater
    4. no output
  10. Question: If the input to the program segment at the right is 85, what is its output?
    
    scanf("%d", &s);
    
    if (s >= 90)
    
    	printf("A\n");
    
    else if (s >= 70)
    
    	printf("C\n");
    
    else if (s >= 80)
    
    	printf("B\n");
    
    else
    
    	printf("D\n");
    
    
     
    Choose the best Answer :
    1. A
    2. B
    3. C
    4. D
  11. Question: What will be the value of i after the C statements at the right have been executed?
    
     i = 3;
    
     j = 10;
    
     if ((3 * i) < j)
    
         { i = i + 2; }
    
     i = i + 3;
    
    
     
    Choose the best Answer :
    1. 5
    2. 6
    3. 8
    4. 10
    5. 15
  12. Question: Assuming that A = 1 and B = 1,
     
    Choose the best Answer :
    1. (A and B) is FALSE, while (A or B) is TRUE
    2. (A and B) is FALSE, while (A or B) is FALSE
    3. (A and B) is TRUE, while (A or B) is TRUE
    4. (A and B) is TRUE, while (A or B) is FALSE
  13. Question: Text enclosed in /* */ in a C program _________.
     
    Choose the best Answer :
    1. gives instructions to the processor
    2. declares memory requirements
    3. makes files available
    4. causes a syntax error
    5. is ignored by the C compiler
  14. Question: The constant 0.15e+6 represents the same value as __________.
     
    Choose the best Answer :
    1. 150000
    2. 6.15
    3. 0.75
    4. 0.21
    5. none of the above
  15. Question: The symbol = is the C equality operator.
     
    Choose the best Answer :
    1. true
    2. false
  16. Question: This assignment statement stores the sum of b and c in a:
    
    b + c = a;
    
     
    Choose the best Answer :
    1. true
    2. false
  17. Question: Which one of the following expressions does not evaluate to 3?
    
    
    Choose the best Answer :
    1. 2 + 16 % 5
    2. 7 - 15 / 4
    3. 6 * 5 / 10
    4. 2 - 4 * 3 + 26 / 2
    5. 8 - 5
  18. Question: "All values stored in memory are represented as binary strings, patterns of zeros and ones."
     
    Choose the best Answer :
    1. true
    2. false
  19. Question: A type char literal is enclosed in single quotes.
    
    
    Choose the best Answer :
    1. true
    2. false
  20. Question: What is the effect of the following code?
    
    int i, total ;       
    
    for (i = 1 ; i <= 15 ; i++)      {        
    	if ( i % 3 == 0)   {           
    		printf("%d  ", i) ;        
    	}     
    }     
    printf("\n\n"); 
    
     
    Choose the best Answer :
    1. It prints out the integers from 3 to 15
    2. It prints out the multiples of 3 from 3 to 15
    3. It prints out the sum of the integers from 3 to 15
    4. It prints out the sum of the multiples of 3 from 3 to 15