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

Discussion

#include <stdio.h> 
struct st 
{ 
    int x; 
    struct st next; 
}; 
   
int main() 
{ 
    struct st temp; 
    temp.x = 10; 
    temp.next = temp; 
    printf("%d", temp.next.x); 
    return 0; 
}

 

  • A.Compiler Error
  • B.10
  • C.Runtime Error
  • D.Garbage Value

Answer: A

Correct answer: Compiler Error

A structure cannot contain an instance of itself - the type would be infinitely large, since each copy would contain another. The compiler rejects struct st next;. What is allowed is a pointer to the same type, struct st *next;, since a pointer has a fixed size; that is how linked lists are built.

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

Post your comment

Please log in or register to post a comment.