C | Structure & Union | Question 5

filter_none

edit
close

play_arrow

link
brightness_4
code

#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; 
}

chevron_right


(A) Compiler Error
(B) 10
(C) Runtime Error
(D) Garbage Value


Answer: (A)

Explanation: A structure cannot contain a member of its own type because if this is allowed then it becomes impossible for compiler to know size of such struct. Although a pointer of same type can be a member because pointers of all types are of same size and compiler can calculate size of struct

Quiz of this Question

Don’t stop now and take your learning to the next level. Learn all the important concepts of Data Structures and Algorithms with the help of the most trusted course: DSA Self Paced. Become industry ready at a student-friendly price.

My Personal Notes arrow_drop_up