Pointers
August 28, 2024
Software-Engineering
August 28, 2024
Pointers
August 28, 2024
Software-Engineering
August 28, 2024

Pointers

Question 16
Assume that float takes 4 bytes, predict the output of following program.
#include
int main()
{
float arr[5]={12.5,10.0,13.5,90.5,0.5};
float *ptr1=&arr[0];
float *ptr2=ptr1+3;
printf(“%f”,*ptr2);
printf(“%d”,ptr2-ptr1);
return 0;
}
A
90.500000 3
B
90.500000 12
C
10.000000 12
D
0.500000 3
Question 16 Explanation: 
● float *ptr1=&arr[0]; // ptr1 will point to first element of the array.
● float *ptr2=ptr1+3; // ptr2 will point to fourth element of the array
● printf(“%f”,*ptr2); // It will display fourth element value which is 90.500000
● printf(“%d”,ptr2-ptr1); // Here both pointer will point to same array . The subtraction operation gives the number of elements between the addresses.
Correct Answer: A
Question 16 Explanation: 
● float *ptr1=&arr[0]; // ptr1 will point to first element of the array.
● float *ptr2=ptr1+3; // ptr2 will point to fourth element of the array
● printf(“%f”,*ptr2); // It will display fourth element value which is 90.500000
● printf(“%d”,ptr2-ptr1); // Here both pointer will point to same array . The subtraction operation gives the number of elements between the addresses.

Leave a Reply

Your email address will not be published. Required fields are marked *