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

Discussion

What will be the output of the following C code?

#include <stdio.h>
    typedef struct student
    {
        char *a;
    }stu;
    void main()
    {
        struct stu s;
        s.a = "hi";
        printf("%s", s.a);
    }

 

  • A.Compile time error
  • B.Varies
  • C.hi
  • D.h

Answer: A

Correct answer: Compile time error

The declaration }stu; makes stu a type name, and its struct tag is student. So struct stu s; asks for a structure whose tag is stu, and no such tag exists. Either stu s; or struct student s; would compile; mixing the two forms is what fails.

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

Post your comment

Please log in or register to post a comment.