wujr5 / c-and-cpp-language-learning

C和C++编程语言学习 - 2015级
67 stars 34 forks source link

计科:第四次课 选择题 #9

Open wujr5 opened 8 years ago

wujr5 commented 8 years ago
  1. Which datatype is used to represent the absence of parameters? a) int b) short c) void d) float
  2. The value 132.54 can represented using which data type? a) double b) void c) int d) bool
  3. Is bool a fundamental datatype in C++? a) Yes b) No, it is a typedef of unsigned char c) No, it is an enum of {false,true} d) No, it is expanded from macros
  4. What is the value of the bool?

    bool is_int(789.54)

    a) True b) False c) 1 d) none of the mentioned

  5. How many characters are specified in the ASCII scheme? a) 64 b) 128 c) 256 d) none of the mentioned
  6. Select the right option. Given the variables p, q are of char type and r, s, t are of int type

    1. t = (r * s) / (r + s);
    2. t = (p * q) / (r + s);

    a) 1 is true but 2 is false b) 1 is false and 2 is true c) both 1 and 2 are true d) both 1 and 2 are false

  7. What is the output of the following program?

    1.      #include <iostream>
    2.      using namespace std;
    3.      int main()
    4.      {
    5.          int x = -1;
    6.          unsigned int y = 2;
    7.   
    8.          if(x > y) {
    9.              cout << "x is greater";
    10.         } else {
    11.             cout << "y is greater";
    12.         }
    13.     }

    a) x is greater b) y is greater c) Implementation defined d) Arbitrary

  8. What is the value of the following 8-bit integer after all statements are executed?

    int x = 1;
    x = x << 7;
    x = x >> 7;

    a) 1 b) -1 c) 127 d) Implementation defined

  9. Which of the following is not one of the sizes of the floating point types? a) short float b) float c) long double d) double
  10. What is the output of this program?

    1.      #include <iostream>
    2.      using namespace std;
    3.      int main()
    4.      {
    5.          float num1 = 1.1;
    6.          double num2 = 1.1;
    7.          if (num1 == num2)
    8.             cout << "stanford";
    9.          else
    10.            cout << "harvard";
    11.         return 0;
    12.     }

    a) harvard b) stanford c) compile time error d) runtime error

SaltyFish123 commented 8 years ago

大哥,这是程设星期一交的题目吗?

wujr5 commented 8 years ago

1 Which datatype is used to represent the absence of parameters?
a) int
b) short
c) void
d) float

Answer:c
Explanation: void will not return anything.

2 The value 132.54 can represented using which data type?
a) double
b) void
c) int
d) bool

Answer:a
Explanation: The given value is with decimal points,
so float or double can be used.

3 Is bool a fundamental datatype in C++?
a) Yes
b) No, it is a typedef of unsigned char
c) No, it is an enum of {false,true}
d) No, it is expanded from macros

Answer:a
Explanation: C++ has bool as a fundamental data type.

4 What is the value of the bool?

bool is_int(789.54)

a) True
b) False
c) 1
d) none of the mentioned

Answer:b
Explanation: The given number is a double not an integer, 
so the function returns 0 which is boolean false.

5 How many characters are specified in the ASCII scheme?

a) 64
b) 128
c) 256
d) none of the mentioned

Answer:b
Explanation: 标准ASCII定义128个字符.

6 Select the right option. Given the variables p, q are of char type and r, s, t are of int type

1. t = (r * s) / (r + s);
2. t = (p * q) / (r + s);

a) 1 is true but 2 is false
b) 1 is false and 2 is true
c) both 1 and 2 are true
d) both 1 and 2 are false

Answer:c
Explanation: Every character constant has an integer value.
Also char belongs to the integral type hence arithmetic and
logical operations can be performed on them.

7 What is the output of the following program?

1.      #include <iostream>
2.      using namespace std;
3.      int main()
4.      {
5.        int x = -1;
6.          unsigned int y = 2;
7.   
8.          if(x > y) {
9.            cout << "x is greater";
10.       } else {
11.         cout << "y is greater";
12.       }
13.     }

a) x is greater
b) y is greater
c) Implementation defined
d) Arbitrary

Answer:a
Explanation: x is promoted to unsigned int on comparison.
On conversion x has all bits set, making it the bigger one.

8 What is the value of the following 8-bit integer after all statements are executed?

int x = 1;
x = x << 7;
x = x >> 7;

a) 1
b) -1
c) 127
d) Implementation defined

Answer:a
Explanation: 原值最低八位为:0000 0001,先左移7位,变成:1000 0000;
再右移7位,变成:0000 0001

9 Which of the following is not one of the sizes of the floating point types?

a) short float
b) float
c) long double
d) double

Answer:a
Explanation:Floating point types occur in only three sizes-float,
long double and double.

10 What is the output of this program?

1.      #include <iostream>
2.      using namespace std;
3.      int main()
4.      {
5.          float num1 = 1.1;
6.          double num2 = 1.1;
7.          if (num1 == num2)
8.             cout << "stanford";
9.          else
10.            cout << "harvard";
11.         return 0;
12.     }

a) harvard
b) stanford
c) compile time error
d) runtime error

Answer:a
Explanation:Float store floating point numbers with 8 
place accuracy and requires 4 bytes of Memory. 
Double has 16 place accuracy having size of 8 bytes.