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 13025
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 12517
Q:

What will output when you compile and run the following code?

#include <stdio.h>
struct student
{

int roll;
int cgpa;
int sgpa[8];

};

void main()
{

struct student s = { 12,8,7,2,5,9 };
int *ptr;
ptr = (int *)&s;
clrscr();
printf( "%d", *(ptr+3) );
getch();

}

A) 8 B) 7
C) 2 D) Compiler error
 
Answer & Explanation Answer: C) 2

Explanation:
Report Error

View Answer Report Error Discuss

Filed Under: Programming

1 12373
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 12275
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 11952
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 11924
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 11184
Q:

What would be the output of the following program ?

main()

{

     const int x = 5; 

      int *ptrx;

      ptrx = &x;

      *ptr = 10;

       printf ("%d", x);

}

A) 5 B) 10
C) Error D) Garbage value
 
Answer & Explanation Answer: B) 10

Explanation:
Report Error

View Answer Report Error Discuss

Filed Under: Programming

2 11171