Machine-translated by Google. Questions are authored in English.
Top

Discussion

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 = 5.5f;
 printf("%f", ptr->f);
 return 0;
}

 

  • A.5.5
  • B.5
  • C.5.5

Answer: C

Here test is a structure name which consist of three variables of three different data types. ptr is the pointer variable, for which the memory is allocated dynamically by using malloc() of function and then it is pointed towards the structure floating variable f. Now f is initialized with a value 5.5f and then outputted as 5.500000.

No comment is present. Be the first to comment.
Loading…

Post your comment

Please log in or register to post a comment.