As far as I know when creating elements dynamically like that there is no way to find out the number of elements (as it's just a pointer) so sizeof wont work. Either keep track of the number yourself (in this case 'm') or use vectors.
Obviously, B being a m_lines x p_columns (2D) array, the number of its elements is simply the product...m*p. Each of m lines has p elements...That's all!