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

Discussion

What will be the output of the following C code?

#include <stdio.h>
enum sanfoundry
{
    a=1,b
};
enum sanfoundry1
{
    c,d
};
int main()
{
    enum sanfoundry1 s1=c;
    enum sanfoundry1 s=a;
    enum sanfoundry s2=d;
    printf("%d",s);
    printf("%d",s1);
    printf("%d",s2);
}

 

  • A.Error
  • B.011
  • C.110
  • D.101

Answer: D

Correct answer: 101

Take each in turn. s1 = c, and in sanfoundry1 c is 0. s = a, and a is 1. s2 = d, which is 1. The prints are in the order s, s1, s2, giving 101. Note that C does not object to assigning a value of one enumeration to a variable of another - they are all just ints.

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

Post your comment

Please log in or register to post a comment.