Top

Discussion

What is the output of this program?

#include 
int main(){
   struct simp 
 {
  int i = 6;
  char city[] = "chennai";
 };
 struct simp s1;
 printf("%d",s1.city);
 printf("%d", s1.i);
    return 0;
}

 

  • A.chennai 6
  • B.Nothing will be displayed
  • C.Runtime Error
  • D.Compilation Error

Answer: D

Compilation Error: Cannot initialize a class member here When we declared members in struture, it just tells the compiler about their presence. There is no memory allocated for that members. So we can't intialize structure members.

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

Post your comment