Programming Questions

Q:

What will be output of following program?


#include <stdio.h>
int main()

{
   void (*p)();
   int (*q)();
   int (*r)();
   p = clrscr;
   q = getch;
   r = puts;
  (*p)();
  (*r)("www.sawaal.com");
  (*q)();
  return 0;
}

A) NULL B) www.sawaal.com
C) Compilation error D) None of above
 
Answer & Explanation Answer: B) www.sawaal.com

Explanation:

p is pointer to function whose parameter is void and return type is also void. r and q is pointer to function whose parameter is void and return type is int . So they can hold the address of such function.

Report Error

View Answer Report Error Discuss

Filed Under: Programming

2 18293
Q:

public abstract interface Frobnicate { public void twiddle(String s); } 

Which is a correct class?

A) public abstract class Frob implements Frobnicate { public abstract void twiddle(String s) { } } B) public abstract class Frob implements Frobnicate { }
C) public class Frob extends Frobnicate { public void twiddle(Integer i) { } } D) public class Frob implements Frobnicate { public void twiddle(Integer i) { } }
 
Answer & Explanation Answer: B) public abstract class Frob implements Frobnicate { }

Explanation:

B is correct, an abstract class need not implement any or all of an interface’s methods

Report Error

View Answer Report Error Discuss

Filed Under: Programming

2 16575
Q:

How many times i value is checked in the below code?

       #include <stdio.h>
        int main()
        {
            int i = 0;
            do {
                i++;
                printf( "In while loopn" );
            } while (i < 3);
        }

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

Explanation:
Report Error

View Answer Report Error Discuss

Filed Under: Programming

5 15786
Q:

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

#include <stdio.h>
void main()

{
    int const SIZE = 5;
    int expr;
    double value[SIZE] = { 2.0, 4.0, 6.0, 8.0, 10.0 };
    expr=1|2|3|4;
    printf ( "%f", value[expr] );
}

A) 2.000000 B) 4.000000
C) 8.000000 D) Compilation error
 
Answer & Explanation Answer: D) Compilation error

Explanation:

Size of any array in c cannot be constantan variable.

Report Error

View Answer Report Error Discuss

Filed Under: Programming

5 15780
Q:

What is the output of this C code?

       #include <stdio.h>
        void main()
        {
            int x = 1, z = 3;
            int y = x << 3;
            printf( "%dn", y );
        }

A) -2147483648 B) -1
C) Run time error D) 8
 
Answer & Explanation Answer: D) 8

Explanation:
Report Error

View Answer Report Error Discuss

Filed Under: Programming

2 14917
Q:

Which of the following statement is true?

A) Cohesion is the OO principle most closely associated with hiding implementation details B) Cohesion is the OO principle most closely associated with making sure that classes know about other classes only through their APIs
C) Cohesion is the OO principle most closely associated with making sure that a class is designed with a single, well-focused purpose D) None
 
Answer & Explanation Answer: C) Cohesion is the OO principle most closely associated with making sure that a class is designed with a single, well-focused purpose

Explanation:

A refers to encapsulation, B refers to coupling

Report Error

View Answer Report Error Discuss

Filed Under: Programming

4 14589
Q:

What will be output of the following c program ?

#include

int main()

{

    int max-val=100;

    int min-val=10;

    int avg-val;

    avg-val =( max-val + min-val ) / 2;

    printf( "%d", avg-val );

    return 0;

}

A) 55 B) 105
C) 60 D) Compilation error
 
Answer & Explanation Answer: D) Compilation error

Explanation:

We cannot use special character – in the variable name.
Variable name can have only underscore.

Report Error

View Answer Report Error Discuss

Filed Under: Programming

5 14577
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 13479