Home / General Knowledge / Testing sawaal :: Discussion

Discussion :: Testing sawaal

  1. What will be output when you will execute following c code?

    #include <stdio.h>
    enum actor

    {
        SeanPenn=5,
        AlPacino=-2,
        GaryOldman,
        EdNorton
    };
    void main()

    {
         enum actor a=0;
         switch(a)

          {
             case SeanPenn:  printf("Kevin Spacey");
                             break;
             case AlPacino:  printf("Paul Giamatti");
                             break;
             case GaryOldman:printf("Donald Shuterland");
                             break;
             case EdNorton:  printf("Johnny Depp");
          } 
    }

  2. A.
    Kevin Spacey
    B.
    Paul Giamatti
    C.
    Donald Shuterland
    D.
    Johnny Depp

    View Answer

    Workspace

    Answer : Option D

    Explanation :


    Default value of enum constant
    GaryOldman = -2 +1 = -1
    And default value of enum constant
    EdNorton = -1 + 1 = 0
    Note: Case expression can be enum constant.


Be The First To Comment