Q73.Marks: +2.0UGC NET Paper 2: Computer Science17th June 2023
What is the output of following code?
main ( )
{static float a [ ] = {13.24, 1.5, 4.5, 5.4, 3.5}
float *j, *k;
j = a;
k = a + 4
j = j * 2;
k = k/2;
printf("% f% f', *j, *k):
}
1.13.25, 4.5
2.1.5, 3.5
3.13.24, 1.5, 4.5, 5.4, 3.5
4.Illegal use of pointer in main function✓ Correct
Solution
The correct answer is Illegal use of pointer in main function
Key Points
The code as written would result in an error due to the illegal use of pointers, so the correct answer would be: Illegal use of pointer in main function
EXPLANATION:
Here are the problems with the code:
Pointers j and k are pointing to the addresses of elements in the array a. However, this line j = j * 2; and this k = k/2; are trying to perform the multiplication and division operations on these pointers, effectively trying to change the addresses they are pointing to.
This is illegal in C as arithmetic operations other than addition and subtraction (for increment and decrement of pointer) are not allowed on pointers.
The syntax of the printf function is incorrect. The correct syntax is with comma (,) instead of colon (:) and you also didn't close the first quotation mark.