adplus-dvertising
frame-decoration

Question

What is the output of this program?
#include <stdio.h>
#include  <stdlib.h>
int main()
{
  struct test
  {
    int i;
    float f;
    char c;
  };
  struct test *ptr;
  ptr = (struct test *)malloc(sizeof(struct test));
  ptr ->f = 2.5f;
  printf("%f", ptr->f);
  return 0;
}

a.

Compilation error

b.

2.5

c.

Garbage value

d.

0

Posted under C Programming

Answer: (b).2.5

Engage with the Community - Add Your Comment

Confused About the Answer? Ask for Details Here.

Know the Explanation? Add it Here.

Q. What is the output of this program?