Programming Questions

Q:

What will be output of following program ?

#include
int main()

{

int a = 10;
void *p = &a;
int *ptr = p;
printf("%u",*ptr);
return 0;

}

A) 10 B) Address
C) 2 D) Compilation error
 
Answer & Explanation Answer: A) 10

Explanation:

Void pointer can hold address of any data type without type casting. Any pointer can hold void pointer without type casting.

Report Error

View Answer Report Error Discuss

Filed Under: Programming

1 14906
Q:

Output of the Program :

main()

{

int i = 1;

while (i <= 5)

    {

         printf( "%d", i );

         if (i > 2) goto here;

         i++;

     }

}

fun()

{

here : printf( "PP" );

}

A) 1 B) 2
C) Compilation error D) Exception occurs
 
Answer & Explanation Answer: C) Compilation error

Explanation:

Compiler error: Undefined label 'here' in function main

Report Error

View Answer Report Error Discuss

Filed Under: Programming

3 14841
Q:

The output of the code below is

       #include <stdio.h>
        void main()
        {
            int i = 0, k;
            if ( i == 0 )
                goto label;
                for ( k = 0;k < 3; k++ )
                {
                    printf( "hin" );
                    label: k = printf( "%03d", i );
                }
         }

A) 0 B) hi hi hi 0 0 0
C) 0 hi hi hi 0 0 0 D) 0 0 0
 
Answer & Explanation Answer: A) 0

Explanation:
Report Error

View Answer Report Error Discuss

Filed Under: Programming

1 14006
Q:

void main()

{

char good *better, *best;

printf( "%d..%d", sizeof(better), sizeof(best) );

}

A) 1..2 B) 4..4
C) 4..2 D) 2..2
 
Answer & Explanation Answer: C) 4..2

Explanation:

The second pointer is of char type and not a good pointer.

Report Error

View Answer Report Error Discuss

Filed Under: Programming

4 13593
Q:

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

#include <stdio.h>
void main()

{
     switch(2)

      {
            case 1L:printf("No");
            case 2L:printf("%s","I");
              goto Love;
            case 3L:printf("Please");
            case 4L:Love:printf("Hi");
     }
}

A) I B) IPleaseHi
C) IHi D) Compilation error
 
Answer & Explanation Answer: C) IHi

Explanation:

It is possible to write label of goto statement in the case of switch case statement.

Report Error

View Answer Report Error Discuss

Filed Under: Programming

3 13411
Q:

What is the output of this C code?

        #include <stdio.h>
        void main()
        {
            int x = 97;
            char y = x;
            printf("%cn", y);
        }

A) a B) 97
C) Run time error D) None
 
Answer & Explanation Answer: A) a

Explanation:
Report Error

View Answer Report Error Discuss

Filed Under: Programming

1 13254
Q:

Which Of The Following Statements Is Most Accurate For The Declaration X = Circle()?

A) x contains a reference to a Circle object B) You can assign an int value to x
C) x contains an object of the Circle type D) x contains an int value
 
Answer & Explanation Answer: A) x contains a reference to a Circle object

Explanation:
Report Error

View Answer Report Error Discuss

10 13061
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 12915