Ex - 1: What is the subtle error in the following code segment?
main()
{
void fun(int, int []);
int n=5,arr[5];
fun(n,arr);
}
void fun(int n, int arr[])
{
int *p=0;
int i=0;
while(i++<N)
p = &arr[i];
*p = 0;
}
Answer & Explanation:
If the body of the loop never executes p is assigned no address. So p remains NULL where *p =0 may result in problem (may rise to runtime error “NULL pointer assignment” and terminate the program).
|