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

Discussion

What is the output of this program?

#include <stdio.h>
int main(){
    struct leader
 {
 char *lead;
 int born;
 };
 struct leader l1 = {"AbdulKalam", 1931};
 struct leader l2 = l1;
 printf("%s %d", l2.lead, l1.born);
}

 

  • A.Compilation error
  • B.Garbage value 1931
  • C.AbdulKalam 1931
  • D.None of the above

Answer: C

Correct answer: AbdulKalam 1931

l2 = l1 copies the structure member by member - the born value and the lead pointer. That is a shallow copy: both structures now point at the same string literal. Here it does no harm, since neither modifies it.

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

Post your comment

Please log in or register to post a comment.