Programming Questions

Q:

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");
      } 
}

A) Kevin Spacey B) Paul Giamatti
C) Donald Shuterland D) Johnny Depp
 
Answer & Explanation Answer: D) Johnny Depp

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.

Report Error

View Answer Report Error Discuss

Filed Under: Programming

1 11503
Q:

What would be the output of the following program ?

main() 

{

       unsigned  int a = oxffff;

        ~a;

        printf ("%x", a);

}

A) ffff B) 0000
C) 00ff D) None of the above
 
Answer & Explanation Answer: A) ffff

Explanation:
Report Error

View Answer Report Error Discuss

Filed Under: Programming

0 11193
Q:

If the following program (myprog) is run from the command line as 

myprog 1 2 3 

what would be the output?

main(int argc, char *argv[])

{

    int i, j = 0;

    for (i = 0; i < argc ; i++)

           j = j + atoi ( argv[i]);

    printf ("%d", j);

}

A) 123 B) 6
C) Error D) "123"
 
Answer & Explanation Answer: B) 6

Explanation:

When atoi() tries to convert argv[0] to a number it cannot do so (argv[0] being a file name) and hence returns a zero.

Report Error

View Answer Report Error Discuss

Filed Under: Programming

2 11082
Q:

What is the output of this C code?

        #include <stdio.h>
        void main()
        {
            int y = 3;
            int x = 5 % 2 * 3 / 2;
            printf("Value of x is %d", x);
        }

A) Value of x is 1 B) Value of x is 2
C) Value of x is 3 D) Compile time error
 
Answer & Explanation Answer: A) Value of x is 1

Explanation:
Report Error

View Answer Report Error Discuss

Filed Under: Programming

2 10809
Q:

The output of the code below is

        #include <stdio.h>
        int *m()
        {
            int *p = 5;
            return p;
        }
        void main()
        {
            int *k = m();
            printf("%d", k);
        }

A) 5 B) Junk value
C) 0 D) Error
 
Answer & Explanation Answer: A) 5

Explanation:
Report Error

View Answer Report Error Discuss

Filed Under: Programming

1 10532
Q:

A source program is the program written in which level language  ?

A) Alpha Numeric B) High-Level
C) Symbolic D) Machine
 
Answer & Explanation Answer: B) High-Level

Explanation:
Report Error

View Answer Report Error Discuss

Filed Under: Programming
Exam Prep: Bank Exams
Job Role: Analyst , Database Administration , IT Trainer

14 10095
Q:

 What is the output of this C code? 

        #include <stdio.h>
        void m()
        {
            printf("hi");
        }
        void main()
        {
            m();
        }

A) hi B) Run time error
C) None D) Varies
 
Answer & Explanation Answer: A) hi

Explanation:
Report Error

View Answer Report Error Discuss

Filed Under: Programming

0 10095
Q:

A function cannot be defined inside another function

A) TRUE B) FALSE
Answer & Explanation Answer: A) TRUE

Explanation:

A function cannot be defined inside the another function, but a function can be called inside a another function.

Report Error

View Answer Workspace Report Error Discuss

Subject: Programming

5 8765