Monday, 13 February 2012

Strip specified character from a string


Q: Write a function that removes all instances of a specified character from a provided string.

A: Function can do that in-place - it needs to maintain two pointers in the string - one (i) that advances and looks for character and zero termination character and another one (j) which follows the first one and points to the place in the string where the next allowed character will be copied. On the return, input string has the same or smaller size than original string.


Thursday, 26 January 2012

How does class members accessibility depend on their access specifiers and class inheritance type?

inheritance type
base class access specifier → derived class access specifier
[ accessible in derived class method? | accessible through derived class object? ]

public:
public       → public          [yes, yes]
protected → protected      [yes, no]
private     → private          [yes, no]

protected:
public      → protected      [yes, no]
protected → protected     [yes, no]
private     → private          [no, no]

private:
public       → private        [yes, no]
protected → private         [yes, no]
private     → private         [no, no]

Sunday, 22 January 2012