Consider the fragment of codes below Explain the difference

Consider the fragment of codes below. Explain the difference between two fragments and which one is better than other why? int arr[1000], *ip; for(ip = &arr;[0]; ip

Solution

Difference between the two code fragments is the how array has been iterated.

In first code fragment array has been iterated with the help of pointer iterable which is initialized with the base address of the array and based on the pointer arithmetic array traversal has been done.

In second code fragment array has been iterated using the indexes in which an integer index variable has been used for iterating the array from 0 to the size of array which is 100.

Complexity wise both will work same but if you see the maintainablilty and structuring of the code second code fragment is much more readable than the first hence, second code fragment is better than the first one.

 Consider the fragment of codes below. Explain the difference between two fragments and which one is better than other why? int arr[1000], *ip; for(ip = &ar

Get Help Now

Submit a Take Down Notice

Tutor
Tutor: Dr Jack
Most rated tutor on our site