×

Loading...
Ad by
  • 推荐 OXIO 加拿大高速网络,最低月费仅$40. 使用推荐码 RCR37MB 可获得一个月的免费服务
Ad by
  • 推荐 OXIO 加拿大高速网络,最低月费仅$40. 使用推荐码 RCR37MB 可获得一个月的免费服务

C++ Test( 一) 答对优秀,我会告诉你可以去哪个AGENCY公司闯关了

本文发表在 rolia.net 枫下论坛Q1: Which of the following has the same result as this fuction declaration?
void NewFun(int[10]);
a) void NewFun(int*);
b) void NewFun(int);
c) void NewFun(int[]);
d) void NewFun(10);
e) both a and c above

Q2: Which statement is NOT true about struct?
a) A struct is a class with public access as the default
b) A struct that is legal in C is legal in C++
c) A struct can contain a union as a member
d) There must be a function declaration within the struct
e) They can be nested (a struct within a struct)

Q3: Which statement is NOT true about inline functions?
a) They typically execute slower than called functions
b) They may be expanded at the point in the program where invoked
c) They return a value of the type stated at definition
d) They are similar(but not identical) to preprocessor macro definitions
e) They can call non-inline functions

Q4: Which of the following is a literal character constant(such as 'a') stored as?
a) a character data tye
b) an integer data type
c) a long integer data type
d) two characters,one to hold the letter and one to hold a null terminator
e) void since it is not a variable

Q5: What must you do in order to compile,link and execute a C function in C++?
a) declare the function as extern "C" in the module calling it and specify its parameters
b) declare the function as import "C" in the module calling it ans specify its parameters
c) overload the C function name for char,int and float data types
d) add an ellipsis(...) to the argument list in the function definition
e) rewrite all of the C code in C++

Q6: Which of the following is true about this statement?
cout << (x>y)?x:y;
a) It outputs the larger of x or y
b) It evaluates as (cout<<(x>y))?x:y;
c) It requires endl in order to print
d) It should be typed within quotation marks
e) It evaluates x and y twice

Q7: Which of the following is true about objects created through dynamic memory allocation (new)?
a) They are automatically deleted when the function in which they were created terminates
b) They are initialized to zero when first created
c) They are given random names assigned by the compiler
d) They are to be deleted by invoking delete
e) They are reorganized via garbage collection if memory becomes exhausted

Q8: Which of the following are true about derived classes?
a) All of their members public by default
b) They have inheritance of all members of their base class including any base constructors
c) They have a public base class if no access keyword is specified
d) They have a public base class if they have some public members
e) They have a public base class if the visibility of all inherited member is maintained

Q9: Which of the following takes place within a class?
a) Member functions can only access public members of the class
b) Information can be hidden from friends by declaring data members as private
c) Constructors can be used to manage initializations
d) Protected members behave as private members to derived classes
e) There must be at least one member function defined

Q10: Which of the following is true about the extraction operator (>>)?
a) It is used extensively by the stream library,but can be defined to do any operation
b) It allows whitespace characters if within quoted strings
c) It is used to direct output to the printer
d) It cannot be overloaded
e) It has a higher precedence than the bitwise shift operator

Q11: For what reason are formal arguments,such as argv and argc,typically given to main()?
a) to prohibit recursive calls
b) to provide interrupt vectors for hardward
c) to act as error handing flags
d) to allow passing of information from the command line
e) to deal with graphical screen control

Q12: With which of the following should pointers NOT be used?
a) casted tye conversions
b) character strings
c) names of functions
d) static class members
e) objects that have been deallocated

Q13: Operators can be overloaded by the programmer:
a) to take an arbitrary number of arguments
b) if they are any of the C++ operators
c) by creating a new operator not in the C++ list
d) to extend the meaning of an operator to objects of a class
e) to override the predefined meaning for operations on built-in data types

Q14: Which of the following is NOT true about user-defined conversions?
a) They can be used in assignments
b) They can be used in initializations
c) They can be applied if there are ambiguities
d) They can be inherited
e) They can be virtual

Q15: Which of the following is true about volatile objects?
a) They are always destroyed using delete()
b) They should always be accessed from memory by the code generated by the compiler
c) They are accesses to out-of-bounds array locations
d) They result from class conflicts
e) They can have only bitwise operations performed

Q16: Which of the following is true about classes defined as type union?
a) They change size depending on what is currently stored
b) They can have static data members
c) They can have objects that define constructors
d) They can have objects that define destructors
e) They have their nonstatic member variables stored at the same address

Q17: What must be true in order to overload functions?
a) They do not have the same name
b) They are not defined
c) They have the exact same argument types
d) They are unique in the number,type or order of arguments
e) They are not declared in .h files

Q18: Which of the following is true of multiple inheritance?
a) There is always a single base class
b) Private members that are inherited are not directly accessible
c) Inherited protected members are only accessible to their immediate successor
d) Ambiguous references are resolved by the compiler
e) All virtual functions must be fully defined

Q19: After the following code segment is executed, on an 8-bit machine,what is DEF?
int XYZ,ABC,CHI,DEF;
XYZ = ~5;
ABC = 20|XYZ;
CHI = ABC&XYZ;
DEF = ABC^XYZ;
a) 5
b) 25
c) 4
d) -1
e) -6

Q20: After the following code segment is executed,what is the value of c?
int a,b,c;
a=5;
b=(a>=6);
c=26*b==0;

a) 52
b) 0
c) 1
d) 6
e) undefined更多精彩文章及讨论,请光临枫下论坛 rolia.net
Sign in and Reply Report

Replies, comments and Discussions:

  • 工作学习 / IT技术讨论 / C++ Test( 一) 答对优秀,我会告诉你可以去哪个AGENCY公司闯关了
    本文发表在 rolia.net 枫下论坛Q1: Which of the following has the same result as this fuction declaration?
    void NewFun(int[10]);
    a) void NewFun(int*);
    b) void NewFun(int);
    c) void NewFun(int[]);
    d) void NewFun(10);
    e) both a and c above

    Q2: Which statement is NOT true about struct?
    a) A struct is a class with public access as the default
    b) A struct that is legal in C is legal in C++
    c) A struct can contain a union as a member
    d) There must be a function declaration within the struct
    e) They can be nested (a struct within a struct)

    Q3: Which statement is NOT true about inline functions?
    a) They typically execute slower than called functions
    b) They may be expanded at the point in the program where invoked
    c) They return a value of the type stated at definition
    d) They are similar(but not identical) to preprocessor macro definitions
    e) They can call non-inline functions

    Q4: Which of the following is a literal character constant(such as 'a') stored as?
    a) a character data tye
    b) an integer data type
    c) a long integer data type
    d) two characters,one to hold the letter and one to hold a null terminator
    e) void since it is not a variable

    Q5: What must you do in order to compile,link and execute a C function in C++?
    a) declare the function as extern "C" in the module calling it and specify its parameters
    b) declare the function as import "C" in the module calling it ans specify its parameters
    c) overload the C function name for char,int and float data types
    d) add an ellipsis(...) to the argument list in the function definition
    e) rewrite all of the C code in C++

    Q6: Which of the following is true about this statement?
    cout << (x>y)?x:y;
    a) It outputs the larger of x or y
    b) It evaluates as (cout<<(x>y))?x:y;
    c) It requires endl in order to print
    d) It should be typed within quotation marks
    e) It evaluates x and y twice

    Q7: Which of the following is true about objects created through dynamic memory allocation (new)?
    a) They are automatically deleted when the function in which they were created terminates
    b) They are initialized to zero when first created
    c) They are given random names assigned by the compiler
    d) They are to be deleted by invoking delete
    e) They are reorganized via garbage collection if memory becomes exhausted

    Q8: Which of the following are true about derived classes?
    a) All of their members public by default
    b) They have inheritance of all members of their base class including any base constructors
    c) They have a public base class if no access keyword is specified
    d) They have a public base class if they have some public members
    e) They have a public base class if the visibility of all inherited member is maintained

    Q9: Which of the following takes place within a class?
    a) Member functions can only access public members of the class
    b) Information can be hidden from friends by declaring data members as private
    c) Constructors can be used to manage initializations
    d) Protected members behave as private members to derived classes
    e) There must be at least one member function defined

    Q10: Which of the following is true about the extraction operator (>>)?
    a) It is used extensively by the stream library,but can be defined to do any operation
    b) It allows whitespace characters if within quoted strings
    c) It is used to direct output to the printer
    d) It cannot be overloaded
    e) It has a higher precedence than the bitwise shift operator

    Q11: For what reason are formal arguments,such as argv and argc,typically given to main()?
    a) to prohibit recursive calls
    b) to provide interrupt vectors for hardward
    c) to act as error handing flags
    d) to allow passing of information from the command line
    e) to deal with graphical screen control

    Q12: With which of the following should pointers NOT be used?
    a) casted tye conversions
    b) character strings
    c) names of functions
    d) static class members
    e) objects that have been deallocated

    Q13: Operators can be overloaded by the programmer:
    a) to take an arbitrary number of arguments
    b) if they are any of the C++ operators
    c) by creating a new operator not in the C++ list
    d) to extend the meaning of an operator to objects of a class
    e) to override the predefined meaning for operations on built-in data types

    Q14: Which of the following is NOT true about user-defined conversions?
    a) They can be used in assignments
    b) They can be used in initializations
    c) They can be applied if there are ambiguities
    d) They can be inherited
    e) They can be virtual

    Q15: Which of the following is true about volatile objects?
    a) They are always destroyed using delete()
    b) They should always be accessed from memory by the code generated by the compiler
    c) They are accesses to out-of-bounds array locations
    d) They result from class conflicts
    e) They can have only bitwise operations performed

    Q16: Which of the following is true about classes defined as type union?
    a) They change size depending on what is currently stored
    b) They can have static data members
    c) They can have objects that define constructors
    d) They can have objects that define destructors
    e) They have their nonstatic member variables stored at the same address

    Q17: What must be true in order to overload functions?
    a) They do not have the same name
    b) They are not defined
    c) They have the exact same argument types
    d) They are unique in the number,type or order of arguments
    e) They are not declared in .h files

    Q18: Which of the following is true of multiple inheritance?
    a) There is always a single base class
    b) Private members that are inherited are not directly accessible
    c) Inherited protected members are only accessible to their immediate successor
    d) Ambiguous references are resolved by the compiler
    e) All virtual functions must be fully defined

    Q19: After the following code segment is executed, on an 8-bit machine,what is DEF?
    int XYZ,ABC,CHI,DEF;
    XYZ = ~5;
    ABC = 20|XYZ;
    CHI = ABC&XYZ;
    DEF = ABC^XYZ;
    a) 5
    b) 25
    c) 4
    d) -1
    e) -6

    Q20: After the following code segment is executed,what is the value of c?
    int a,b,c;
    a=5;
    b=(a>=6);
    c=26*b==0;

    a) 52
    b) 0
    c) 1
    d) 6
    e) undefined更多精彩文章及讨论,请光临枫下论坛 rolia.net
    • 我胡乱做了一下,请不要见笑。'_'代表不会做 c, d, a, a, a, a, d, b, c, a, d, e, b, _, _, a, d, b, c, c
    • 1.a 2.b 3.a 4.b 5.a 6.a 7.d 8.c 9.d 10.a 11.d 12.e 13.d 14.c 15.b 16.e 17.c 18.c 19.b 20.e
    • 呵呵,这题的难度看,大概是过AGENT那关的巴, 公司那关难度应该大很多,而且要更重实机用但书上没有的
    • 1. a 2. d 3.a 4. a 5.a 6. b 7.d 8.e 9.c 10.a 11.d 12. d 13. e 14. c 15. b16. e 17.d 18. c 19. c 20.c
      • This is the standard answer.
        • thanks a lot.Can you give me more answers for other questions?再谢 :)
        • 请提供test(2)的standard answer. Thanks
        • no, you are wrong. 8.b 12.e
    • EDBAC ACCBA DECCB CBEEA
      • 19和20题是瞎选的。高手的正确答案公布一下
    • 1.e 2.b 3.a 4.a 5.a 6. a 7. d 8.c 9.c 10.a 11.d 12.e 13.e 14.c 15.b 16.e 17.d 18.c 19.c 20.c
      • 第6题是b,TMD,我以前也没注意到 conditional expression 和 << 优先级的问题,可是话说回来,出了出题者搞搞乐子外,哪有这样 写程序的?
        • 看了楼上的弟兄才想起6问题啊,优先级顺序都忘了。12题是猜了,C++还未编过程,只是稍微学了点,不全。
      • 12题应该是d吧,指向objects that have been deallocated 的指针是NULL呀,static class member是没有this指针的,我不知道出题者是不是这个意思。其它的答案我赞同。
        • I guess the question was about a pointer to a static class memeber, what's wrong with that? This set of questions are very vague and not practical enough.
        • 这不是指this指针,当然可以有指针指向static member
      • 1)e d a a 5)a a d c 9)b b d d 13)d c b e 17) d b c c
        • 2) all legal C structure is legal in C++. But no function must be defined in a structure. So ans should be d see inside and AS IS
          9) private member is protect from any friend and derived class. but I am not sure about c)10) >> do not exist in any lib. and it allow space charater
          12) static class member do not allowed pointer, it like a global varible
          13) inbuild data operator does not allow override
          18) xyz=0xfffffffa abc=0xfffffffe xor result should be 4, so ans should be c
          As is.
    • I am not a CP guy, but your post is really useful and I will copy and store. Why so many persons have different anwers?
    • C++ TEST(二) -------注:先不管它的难度如何,这四十多道题目是TORONTO一家AGENT目前的真实考题,他们的要求是至少答对75%以上才和你谈。老实说,标准答案我也没有,所以放在这里和大家一起讨论。不过我知道前四题的答案应是a,d,b,a,
      本文发表在 rolia.net 枫下论坛Q21: For the following code segment,which is correct?
      enum font{pica,elite=5,boldface}type;
      type=boldface;
      a) type has numeric value 6
      b) type has numeric value 3
      c) pica has numeric value 1
      d) type is an integer
      e) font is an integer

      Q22: What is the following line of code an example of?
      speed=(rpm>45)?78:((rpm<45)?33.33:45);
      a) looping
      b) nested conditionals
      c) casting
      d) good programming style
      e) auto-increment

      23: For the following structure,what does employee[5].first[1] return?
      struct name{
      char first[10];
      char last[20];
      } employee[350];
      a) the 1st letter of the first name of the 5th employee
      b) the 2nd letter of the first name of the 6th employee
      c) the 1st letter of the first name of the 6th employee
      d) the first name of the 5th employee
      e) the first name of the 6th employee

      Q24: What is the function of the code ofstream outFile("myfile",ios:app);?
      a) It doesn't create a file if the named one doesn't exist
      b) It opens the file and seeks to the end for writing
      c) It allows reading of the file
      d) It overwrites the file info
      e) It adds data to the end of the file

      Q26: Which of the following is true about the index variable in a for loop?
      a) It is initialized at the end of the loop
      b) It is never incremented or decremented
      c) It should be compared to a variable that changes inside of the loop
      d) It counts the loop repetitions
      e) It must be auto-incremented

      Q27: Which of the following is true about a static storage class variable,when declared with a function?
      a) It has scope throughout the entire program
      b) It is reinitialized each time its block is entered
      c) It has a variable name that cannot be used by other functions
      d) It retains its value between function calls
      e) It is reserved prior to the actual declaration

      Q28: Which should NOT be part of the comments in a function header?
      a) name of the function
      b) input to the function
      c) actual value returned by the function
      d) external variables affected by the function
      e) purpose of the function

      Q29: Which of the following occurs in a switch statement?
      a) Breaks are always required
      b) The default is always executed
      c) Case values are always compared to the switch variable
      d) The cases must be in numeric order
      e) Curly brackets are never used

      Q30: Which of the following are NOT true about the statement below?
      for(expr1;expr2;expr3)
      { statement_1;
      statement_2;
      .....
      statement_n;
      }
      a) statement_1 cannot be a function call
      b) if expr1 and expr3 are null it is the same as a while loop
      c) any of expr1,expr2,expr3 can be omitted
      d) break can terminate the loop
      e) another for can be nested

      Q31: What do the following lines of code have in common?
      result = ( 1 && 0 ) || 6;
      result = ( 1 & 0 ) | 6;
      a) They both store the same value in result
      b) They both evaluate as true
      c) They both evaluate as false
      d) They both store 6 in result
      e) They both store 1 in result

      Q32: What is the result of this code segment?
      int x = 4;
      float y = 0.00;
      char z;
      z = x + y;
      a) z contains the character '4'
      b) z contains 4.0
      c) z's value is undetermined
      d) A runtime error occurs
      e) z contains 4

      Q33: Which of the following is true for the bitwise left shift operation?
      a) The high bit is rotated in on the right
      b) Vacated bits are always filled with 0's
      c) The result is system dependent
      d) Floats may be used
      e) The sign bit never changes

      Q34: Which of the following is true about recursive functions?
      a) They are often shorter than iterative ones
      b) They can never call themselves
      c) They do not need persistent data types
      d) They involve stack space that is allocated through explicit declaration
      e) They may only be invoked once

      Q35: Which of the following is a feature of a good user interface?
      a) It uses color whenever possible
      b) It is consistent throughout the application
      c) It redefines the keyboard for ease of use
      d) It uses the mouse exclusively
      e) It contains windows

      Q36: Which of the following can valid C++ statements NOT do?
      a) produce overflow errors
      b) contain nested assignment
      c) assign values within the clause of an if statement
      d) call undefined functions
      e) use promotion of data types

      Q37: Which of the following is true about variables declared as extern?
      a) They are always accessible at each program line
      b) They may be set from within a function
      c) They have values that never change
      d) They may not be initialized
      e) They can only be used as pointers

      Q38: For which of the following can escape sequences NOT be used?
      a) entering single characters
      b) page control
      c) formatting output
      d) unquoted literal strings
      e) tabs

      Q39: Which of the following is true about the body of a while loop?
      a) It must change the index variable
      b) It will always be executed once
      c) It is skipped if the starting condition is false
      d) It cannot call a function
      e) It cannot affect the while condition

      Q40: On which of the following should the addtion operation NOT be performed?
      a) the value returned by a pointer to an integer
      b) a single pointer
      c) mixed data types
      d) character variables
      e) two pointers

      Q41: Which of the following is true about a function declared as void?
      a) It cannot affect global variables
      b) It returns only a 0 value
      c) It has no statements in its body
      d) It will be defined by a #include file
      e) It cannot be invoked in an experssion expecting a return value更多精彩文章及讨论,请光临枫下论坛 rolia.net
      • 不,前四道题应为e,d,a,a
        1。数组两种形参[], *都可以。
        3。inline函数运行速度较快,但代码效率低
        • 第一题应该a, a[]做参数不行:(
          • 不,int * = int[] = int[10],当传递parameter的时候。(其实传的都是指向 stack中array的第一个element.
            • 地址。TNND,漏敲了
          • a[]做形参,可以的。我曾试过,*a 和a[做形参,都可以。如有问题,那是C编译器不同。
        • I agree with others, but for No.1, I think the answer should be c. An int array variable is actually equilvalent to int* const , a.k.a constant pointer to intergers.
          It's almost the same as int* when you pass it as parameters(because C++ pass param. by value), but compiler might give some warning. Let me try it out on gcc.
          • It looks that the g++ didn't complain, so I agree with you
        • 抱歉,什么叫“inline函数运行速度较快,但代码效率低”? 应该是目标代码 较大吧,所以你选a就错了,呵呵
          • sorry,俺没看见是NOT TURE, :( ...
      • Can someone take a look at No.29, the one about switch statement, I suspect none of the choices is right.
        • i think D.How do you feel?
          • But in D, it says that the cases have to be in numeric ORDER, I understand the value after case has to be of integral type, but they don't have to be in a particular order(descending or ascending).
            • I guess it is C
              • I think c is wrong.
                switch i{
                case 1:
                break;
                case 2:
                ...
                }

                Does i compare with 2?I think not.
            • The cases must be in numeric order 可不可以理解为"所有的例子必须是可排序?"
    • these question are not so easy
      if can answer 75% without ref to compiler or book, u can be consider as good C/C++ programmer.
      but on the otherside, not all the good programmer should be able to answer these question correctly, because most of the questions are :written code in bad manner and ask you what does it mean. What you should do is know there could be a problem and avoid write it in such a way, even u are clear abotu it. for example: c=26*b==0; even u know == is the lowest priority, u'd better add a (c=26*b)==0.
      • strongly agree with you at it. easy-understand and simple is very important for coding.
    • reply for C++ Test
      1e, 2a,d 3a,b,c 4b 5a 6a 7d 8d 9c 10b 11d 12e 13d 14c 15b
      16e 17d 18a 19c 20c
    • faint! I can not work out most of them! By the way, I do not think a well-managed company will let programmers write "25^x==6".
    • 1.a 2.d 3.a 4.a 5.a 6.b 7.d 8.e 9.c 10.a 11.d 12.e 13.d 14.c 15.b 16.e 17.d 18.b 19.c 20.c 21.a 22.b 23.b 24.b 26.d 27.d 28.a 29.c 30.a 31.b 32.e 33.b 34.a 35.b 36.d 37.b 38.d 39.c 40.e 41.e {from:154.5.47.82}
    • 简直是对C++程序员的侮辱!!!这样的代理不谈也吧。
    • tell us which agency it is. It has been posted here for a week and you never say the name of this agency.
    • 是不是RHIC,过了也没用。
    • ?这会把C++的人引入歧途。一点儿OO的概念都没有。