Computer Science, asked by swatisamikshyasahu, 8 months ago

6: Assuming that float consumes 4
bytes, find the output of following
program.
#include <stdio.h>
int main()
{
float arr[5] = {12.5, 10.0, 13.5, 90.5, 0.5);
float *ptr 1 = &arr[0];
float *ptr2 = ptr1 + 3;
printf("%f", *ptr2);
printf("%d", ptr2 - ptr1);
I Loud
return 0;
}

Answers

Answered by demobectranuser121
4

Answer:

mark me as brainlist answer

Explanation:

6: Assuming that float consumes 4

bytes, find the output of following

program.

#include <stdio.h>

int main()

{

float arr[5] = {12.5, 10.0, 13.5, 90.5, 0.5);

float *ptr 1 = &arr[0];

float *ptr2 = ptr1 + 3;

printf("%f", *ptr2);

printf("%d", ptr2 - ptr1);

I Loud

return 0;

}

Answered by qwvilla
0

The output of the given program segment :

#include <stdio.h>

int main()

{

float arr[5] = {12.5, 10.0, 13.5, 90.5, 0.5);

float *ptr 1 = &arr[0];

float *ptr2 = ptr1 + 3;

printf("%f", *ptr2);

printf("%d", ptr2 - ptr1);

I Loud

return 0;

}

will be :-

90.500000

3

  • When we add a value x to a pointer p, the value of the resultant expression is p + x*sizeof(*p) where sizeof(*p) means size of data type pointed by p.
  • That is why ptr2 is incremented to point to arr[3] in the given code.

#SPJ3

Similar questions