How to produce, using a pointer to a pointer, check for zero when dividing?
- oneCheck if pointer points to null pointer or division by zero? - Ildar
- oneClarify the question. What is the division of what, and what's the point? - drdaeman
|
2 answers
Like that
int x = 1; int *y = &x; int **z = &y; if (**z != 0) **z = 1 / **z;
z
is a pointer to y
, y
is a pointer to x
, and x
is an integer that is checked for zero before division. Operations on **z
equivalent to operations on x.
- Better: <pre> int x = 1; int * y = & x; int ** z = & y; ... if (z! = NULL) if (* z! = NULL) // otherwise dereference the NULL pointer and come! // Well, or comparison with null_ptr - what is there in the PL. if (** z! = 0) ** z = 1 / ** z; </ pre> - gecube
|
try { //Делаешь что надо } catch(Exception &e) { // Здесь что надо сделать если неполучилось }
|