Predict the outputs of following C programs.
Question 1
Output: Compiler Error
In C, static variables can only be initialized using constant literals. See
this GFact for details.
Question 2
Output: Infinite times GeeksforGeeks
The loop termination condition never becomes true and the loop prints GeeksforGeeks infinite times. In general, if a
for or
while statement uses a loop counter, then it is safer to use a relational operator (such as <) to terminate the loop than using an inequality operator (operator !=). See
this for details.
Question 3
Output: Compiler Error
A C 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.
Please write comments if you find any of the answers/explanations incorrect, or you want to share more information about the topics discussed above