A not very experienced programmer sends us the following
function and tells us that it exchanges the values of the two
parameters. If it is called as swap(x, y)
, after execution,
variables x
and y
have exchanged their
values. Is this true? Check your answer creating a program in your
development environment and executing it. You may print an integer
variable x
with the line printf("%d\n",
x);
.
1 2 3 4 5 6 7 8 | void swap(int a, int b) { int tmp; tmp = a; a = b; b = tmp; return; } |
The same programmer sends us a second function that given an array of integers, it increases in one unit all its elements. Does the function really perform such application? (Hint: The function is defined correctly, it contains no syntax error)
1 2 3 4 5 6 7 8 | void increase(int table[], int size) { int i; for (i = 0; i < size; i++) { table[i]++; } } |
An application manipulates data derived from a Global Positioning System using the following structure:
1 2 3 4 5 6 7 | struct gps_information { int is_3D; float latitude; float longitude; float height; }; |
Write the prototype of a function that receives two
structures of this type and a float
. The function returns
an integer with value 1 if the latitude and longitude of both structures
are apart no more than the value of the third parameter, or zero
otherwise. You must use the data type synonym defined.
Write the function with its complete definition (it
might be useful the library function fabsf
).
Write a function that receives as parameters two arrays
of structures as defined in the previous exercise, an integer with their
size (which is identical for both of them), and a
float
. The function processes the two arrays simultaneously
(first element with first element, second with second, and so on) and
returns the index of the first pair of elements that are near as
calculated by the function of the previous exercise using the last
parameter as distance. If the condition is not fulfilled by any pair or
points, the value -1 is returned.
This function that you just implemented is the one needed in the application and not the one in the previous exercise which is auxiliary and with a reduced scope. Which change would you do in the definition of function in the previous exercise?