Online-Test-Questions

Hello everyone

Could somebody please help me with the correct answers of the following questions asked during an online test? I don't remember the exact code for every question hence am writing the questions in simple English. Syntax may seem incorrect because MS Word formats the text. Apologies for that.

1
2
3
Int p[3] = {2,4,6}
*(p++);
Cout << p[2] << endl;

What does it print?

--------------------------------------------------------------------------------

1
2
3
4
5
6
Class A {}
Class B : public Class A {}
A *pa = new B();
B *bp = new B();
Delete pa;
Delete pb;

What does it do?

--------------------------------------------------------------------------------

If we try to print a VALUE against a KEY but the VALUE does not actually exist in the map against that KEY, what happens?
e-g
1
2
3
4
5
6
KEY	VALUE
1	a
2	b
3	
4	c
5	d

Now if I want to print the value of the 3rd key, what will happen?

--------------------------------------------------------------------------------

1
2
Unsigned int var = 48;
If(var == 38? 15:10)

Is the answer 10?

--------------------------------------------------------------------------------

1
2
3
4
Void doit(int, char*)
Void doit(char*, int)
Float doit(char*)
Float doit(int)

Which ones can be substituted for which ones so that the result is the same?

--------------------------------------------------------------------------------

Accessing previous element of array through a pointer.

--p or p--

Correct syntax?


Many thanks
1: bad code?

*(p++) will increment the pointer, p[2] will then try to read outside of the array and you'll probably get an index out of bounds exception... are you sure you remembered the code right? Maybe it was (*p)++ which would increment the first value from 2 to 3, p[2] is still 6 though.

4: ... I don't know what the if will do there, but var == 38? 15:10 will return 10 when var is anything other than 38.

5: ... without knowing what the internals are... the first two can be swapped as a char* is an int and both return nothing, and the second two can be swapped, same reasons.

6 --p is reduce then use
p-- is use then reduce
so *(--p) would access the previous value.
Last edited on
Thanks ValliusDax. That was very very helpful :)

Could anyone please help me with the rest? I'd be grateful.
Last edited on
Topic archived. No new replies allowed.