University of Texas at Dallas
Erick Jonsson School of Enginering and Computer Science

CS Placement Test

 

    1. What type must a variable be if you want to store the number 9.8987 in it?
      double
      char
      int
      bool

    2. What is the proper way of declaring and initializing a variable in the same line?

      a=int; a = 10;
      a=10 int;
      int a=10;
      it is not possible

    3. What is the value of the variable result after the execution of the following code segment?
    int a=2, b=2, c=6, result;
    result = a * b + a + c / 2;

      8
      6
      10
      9

    4. If two arithmetic operators in an expression have the same precedence, they work according to their:

      prioritizing factor
      associativity
      data types
      maximun numbers

    5. Which of the following is not a valid boolean expression.?

      (1 < x < 100)
      (x != 1) && (y !=10)
      (x >= 5) && (x<=50)
      (x ==y)

    6. Which of the following operators has the highest precedence?

      *
      &&
      ( )
      +=

    7. What is the value of result variable after the execution of the following code segment:

    int a = 8;
    int b = 9;
    int c = 0;
    int result=100;
    if (a != b && c == 0 ) result++;
    else --result;

    99
    100
    0
    101

    8. Which of the loop statements is ideal for situations that require a counter

      The do-while loop
      The for loop
      Nested loops
      The while loop

    9. Convert the following while loop to a for loop

    a = 8; sum=0;
    while ( a > 0 ) { sum = sum + a; a= a - 1; }

     

      for (a=8; sum=0 ; a > 0; a--) sum ++;
      for (a=8, sum =0 ; a > 0; a--) sum += a;
      for (a=8; sum=0 ; a > 0; a=a-1) sum + a;
      for (a=8, sum =0 ; a < 0; a--) sum += a;

    10. How many times will the value in the variable tmp be displayed in the following program segment? (assume output displays the value of the variable).

    int x, y, z; int tmp=0;
    for (x=0; x<2; x++)
    for (y=0; y<2; y++)
    for (z=0; z<2; z++) output (tmp);

      0
      2
      6
      8

    11. What is the value of the variable result after the execution of the following code segment?

    a = 5; result=10;
    while ( a++ < 10 ) { result ++; }


      15
      14
      16
      10


    12. What is the value of the variable result after the following switch statement?

    int result=0;
    int option=1;
    switch (option) {
    case 0: result=result+1;
    case 1: result=result+2;
    case 2: result=result+3;
    }


      1
      2
      3
      5

     

    13. What is the output after the following for statement? (assume output displays the value of the variable).

    for (int i=0; i<10; i++) {
    if (i>=2 && i<=6) continue;
    else output ( i );
    }

      1 2 3 4 5 6 7 8 9
      0 1 7 8 9
      0 1 2 6 7 8 9
      2 3 4 5 6

    14. The _________ statement causes a loop to terminate immediately.

      continue
      quit
      break
      end loop


    15. After declaring an array of 5 integers, what is the output of the following code segment:? (assume output displays the value of the variable)

    for (int i = 0; i < 5; i++) {
    array[i] = i * i ;
    }

    output (array[3] );

      2
      3
      4
      9


    16.Function getValue has ____ parameter(s) and its return type is _____

    double getValue (int x, float y) {
        /* body of the function*/
    }

      2, double
      1, int
      1, float
      2, void


    17. The keyword _______ indicates that a function/method does not return a value.


      nokey
      return
      void
      exit


    18. What is the output of the following segment code after calling the function/method display ?

    void disp ( ) {
        int i=10;
       duplicate ( i );
       output(i);
    }
    static void duplicate (int i) {
       i=i*2;
    }


      0
      10
      20
      syntax error


    19. The scope of a _______ variable starts from its declaration and continues to the end of the block that contains the variable

      static
      local
      global
      public


    20. When passing an array as an argument to a function, the funtion __________

      will pass it by value
      cannot modify the original array
      can modify the original array
      will create a new version of the array