3
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:   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.

Subject: Programming
Q:

Indicate what would the SWAP macro be expanded to on preprocessing. Would the code compile?

#define SWAP (a, b, c ) (c t; t = a, a = b, b = t; )

main()

{

    int x = 10, y = 20;

    SWAP (x, y, int );

    printf ( " %d%d ", x, y);

}

Answer

( int t ; t = a, a = b, b = t ;);


This code won't compile since declaration of t cannot occur within parentheses.


 

Report Error

View answer Workspace Report Error Discuss

Subject: Programming

0 2816
Q:

What would be the output of the following program?

# define SQR(x) (x * x)

main()

{

    int a, b = 3;

    a = SQR ( b + 2 );

    Printf ("\n %d ", a );

}

Answer

11


Because, on preprocessing the expression becomes  a = ( 3 + 2 * 2 + 3),  as Ist preference is multiply & then addition, it evalvates as(3+ 2 * 3 +2) = (3+6+2)=11.

Report Error

View answer Workspace Report Error Discuss

Subject: Programming

1 2146
Q:

How many times the following program would print 'Jamboree'?

main()

{

     printf ( "\nJamboree");

     main ();

}

Answer

Till the stack doesn't overflow

Report Error

View answer Workspace Report Error Discuss

Subject: Programming

2 3525
Q:

Will the following function work?

f1 ( int a, int b )

{

    return ( f2 (20) );

}

f2 ( int a )

{

    return ( a * a );

}

Answer

Yes

Report Error

View answer Workspace Report Error Discuss

Subject: Programming

0 1927
Q:

Point out the error, if any, in the following program.

main()

{

    int a = 10;

    void f();

    a = f();

    printf ( "\n %d", a );

}

void f()

{

    printf ( "\n Hi ");

}

Answer

In spite of defining the function f() as returning void, the program is trying to collect the value returned by f() in the variable a.

Report Error

View answer Workspace Report Error Discuss

Subject: Programming

0 1980
Q:

There is a mistake in the following code. Add a statement in it to remove it.

main()

{

     int a;

     a = f (10, 3.14) ;

     printf ( " %d ", a );

}

f (int aa, float bb)

{

    return ( ( float ) aa + bb );

}

Answer

Add the following function prototype in main ():


float f ( int, float );

Report Error

View answer Workspace Report Error Discuss

Subject: Programming

0 2701
Q:

What would be the output of the following program?

main()

{

    float a = 0.7;

    if ( a < 0.7f )

          printf ( " C ");

    else 

          Printf ( " C++ ");

}

Answer

C++

Report Error

View answer Workspace Report Error Discuss

Subject: Programming

0 1825
Q:

If the binary equivalent of 5.375 in normalised form is 0100 0000 1010 1100 0000 0000 0000 0000, what would be the output of the following program?

main()

{

    float a = 5.375 ;

    char *p;

    int i;

    p = ( char* ) &a ;

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

          printf ( " %02x ", (unsigned char ) p[i] );

}

Answer

00 00 AC 40

Report Error

View answer Workspace Report Error Discuss

Subject: Programming

7 7859