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

Discussion

Predict the output of below code:

#include <stdio.h> 
int main() 
{ 
    struct site 
    { 
        char name[] = "GeeksforGeeks"; 
        int no_of_pages = 200; 
    }; 
    struct site *ptr; 
    printf("%d",ptr->no_of_pages); 
    printf("%s",ptr->name);  
    getchar(); 
    return 0; 
} 

 

  • A.GeeksforGeeks
  • B.Compilation Error
  • C.Runtime Error
  • D.Geeks

Answer: B

Correct answer: Compilation Error

A structure declaration describes a type, not an object, so its members cannot be given initialisers - char name[] = "GeeksforGeeks"; and int no_of_pages = 200; are both rejected. A member array also cannot have an unspecified size. The code therefore fails to compile, and the uninitialised ptr never becomes an issue.

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

Post your comment

Please log in or register to post a comment.