Go4Expert

Go4Expert (http://www.go4expert.com/)
-   C (http://www.go4expert.com/forums/c/)
-   -   I need to answer these question I did my best please correct my answer (http://www.go4expert.com/forums/i-answer-question-i-correct-answer-t23655/)

mocha 24Oct2010 14:07

I need to answer these question I did my best please correct my answer
 
Hello ever one


I need to answer these question I did my best please correct my answer?


1-what is the difference between a variable reference and a variable pointer?
a-A reference is the entire object while a pointer is only the address of it.
b-Reference can only be used as parameters to function or methods.
c-the syntax used to access the object.
d-pointers are simple address to the object while a reference uses the virtual table.
e-There is no difference.

I think the answer is b.


1. A pointer can be re-assigned any number of times while a reference cannot be reassigned after initialization.
2. A pointer can point to NULL while reference can never point to NULL
3. You can't take the address of a reference like you can with pointers
4. There's no "reference arithmetic's" (but you can take the address of an object pointed by a reference and do pointer arithmetic's on it as in &obj + 5).


What is one of the benefits of object oriented programming?

a) Make programming easier.
b) Encapsulation handling.
c) Exception handling.
d) Provide scoping of variables.
e) Allow separate compilation

I think the answer is c .
How can I simplify error handling?
We can use exceptions to improve error handling. These allow us to separate errors from what the main intent of the program is. When you write code to list objects in an array, checking for null or invalid numbers may not be its primary purpose. With exception handling, we can separate the error handling from the really important thrust of the program. Clearer code makes maintenance, and future improvements, easier




3-Given the declaration int i =5 ,j= -1,k=0 ;and the expression i+=j -=k*=i++;
what is are the values after the expression is executed?
a) i=5,j=-1,k=0
b) i=0,j=-6,k=5
c) i=-1,j=-7,k=6
d) i=5,j=0,k=0
e) The expression will not execute. It is not syntactically correct.
I think the answer is a .

4- If tow functions have the same name then when the name is used in the program, what happens?
a) C++ does not allow two functions to have the same name.
b) The functions will be selected based on the return type needed.
c) The functions are both called in the order that they are declared.
d) The first function is always called that is declared first.
e) The functions will be selected based on the parameters.
I think the answer is e .

5-when is the following true? x==y ==x
a) X is 1 and y is 1.
b) X is 0 and y is 0
c) Any values of x and y as long as x==y
d) The expression is never true.
e) The expression is always true.
I think the answer is D .


6-Declared variable with no initialization has what value?
A. 0 for all bytes
B. Null
C. No value
D. Will not compile without initialization
E. A value that is garbage.
I think the answer is D .





7-which loop structure is guaranteed to execute the body of the loop at least once?
A. For loop
B. While loop
C. Do wile loop
D. Non of the avove
E. All of the above.
I think the answer is c.


8- Over loaded functions are
A. Very long functions that can hardly run.
B. One function containing another one or more functions inside it.
C. Tow or more functions with the same name but different number of parameters or parameters of different type.
D. Functions that can use two or more parameters.
E. None of above.
I think the answer is c.


9-which of the STL containers store the elements contiguously (in adjacent memory locations)?
A. Std::vector
B. Std::list
C. Std::map
D. Std::set

I think the answer is c.

10-Which of the following is not recommended in a header file?
A. Type definitions(typedefs)
B. Class definitions
C. Function definitions.
D. Template definitions.
E. Macro definitions.
I think the answer is D or maybe E.

mocha 24Oct2010 14:47

Re: I need to answer these question I did my best please correct my answer
 
and this one too
what is the value of the variables?
Char**a,*b,c ;
a=&b;
*a=&c;
**a='z';

I got this

xpi0t0s 25Oct2010 13:26

Re: I need to answer these question I did my best please correct my answer
 
10. What you need to think about is what would happen if defs.h contained each of A-E, and c1.c and c2.c both #include defs.h, and you try to build c1.c and c2.c into an executable. Would you get some errors? Try it.

9. no idea, you'd have to RTFM. I *think* A-C are based on a linked list, making it D, but I'm not certain.

8. Did you try Googling? http://lmgtfy.com/?q=overloaded+function+c%2B%2B

7. D and E are both wrong. Where is the test in each of A-C? If it's at the start of the loop then the loop body might not be executed at all. If it's at the end then it has to go through the loop at least once before it gets to the test.

6. Very important this one if you want to avoid some really difficult to find bugs. E.

5. Duff question, because it depends on the compiler. If TRUE==1 then a is one possible answer, but it can also be true if x is zero and y is non-zero (because FALSE *is* zero, and x==y==x is equivalent to x==(y==x), or x==(TRUE or FALSE)). If TRUE==-1 then none of A-E because it would be true when x==-1 and y==-1 (as well as when x==0 and y!=x). But maybe a is the answer they're looking for.

4. Correct.

3. Another duff question. Undefined behaviour; the expression abuses the postincrement. You would have to run it in your compiler and see what the output is. In Microsoft Visual Studio this is equivalent to i+=j -=k*=i; i++;, so k*=i->k=0, j-=0->j=-1, i+=-1->i=4, i++->i=5. So i=5,j=-1,k=0. But if the postincrement happens after k*=i++ and before i+=j then the final value of i is 6.

2. Duff question, depends on what your tutor has said, which is probably wrong. Not e,d,b because C has them, and C isn't OO, a is dependent on your point of view (c makes assembly level programming easier), and probably not c either because exceptions aren't unique to C++. But maybe they're after c.

1. Another duff question? a: no, because a reference is actually a pointer but uses different semantics; b:no because you can use references in other contexts; c:no, this isn't a "difference statement"; d:no because vtables are about virtual functions not variables; e:no, because there IS a difference in the way they are used. Check your course notes, one of these statements will incorrectly be labelled as true.

xpi0t0s 25Oct2010 13:31

Re: I need to answer these question I did my best please correct my answer
 
I had a look at the ECDL once (European Computer Driving Licence) and it was full of stupid questions like this. It tests your knowledge of the course notes, *not* your knowledge of computers. I would fail the ECDL, yet I've been a computer professional for over 20 years and amateur since I was 14 (when I started out with a ZX81).

mocha 26Oct2010 04:26

Re: I need to answer these question I did my best please correct my answer
 
The answer is :

1. A
2. B
3. E
4. E
5. A
6. E
7. C
8. C
9. Dont know
10. E

Am agree some questions is not logical right:cuss:

xpi0t0s 27Oct2010 12:23

Re: I need to answer these question I did my best please correct my answer
 
Code:

void test31()
{
        int TRUE=(1==1), FALSE=(1==0);
        int x=0, y=1;
        printf("x==y==x is %s\n",(x==y==x) ? "TRUE" : "FALSE");
}

Output: x==y==x is TRUE

So it's not A, cos x=0 and y=1.


All times are GMT +5.5. The time now is 08:04.