Q. What will be the output of this code?

Code:
void main()
{
      struct xx
      {
            int x=3;
            char name[] = "hello";
      };
      struct xx *s = malloc(sizeof(struct xx));
      printf("%d", s->x);
      printf("%s", s->name); 
}
  • (A) 3 hello
  • (B) Compiler Error
  • (C) Linking error
  • (D) None of these
πŸ’¬ Discuss
βœ… Correct Answer: (B) Compiler Error
Explanation: Initialization should not be done for structure members inside the structure declaration.
Explanation by: Rajeev Malhotra
Initialization should not be done for structure members inside the structure declaration.

πŸ’¬ Discussion


πŸ“Š Question Analytics

πŸ‘οΈ
178
Total Visits
πŸ“½οΈ
4 y ago
Published
πŸŽ–οΈ
Rajeev Malhotra
Publisher
πŸ“ˆ
81%
Success Rate