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:

What would be the output of the following program?

main()

{

    printf (" %d%d%d ", sizeof (3.14f), sizeof (3.14), sizeof (3. 141);

}

Answer

4  8  10

Report Error

View answer Workspace Report Error Discuss

Subject: Programming

0 1870
Q:

Which error are you likely to get when you run the following program?

main()

{

  struct emp

  {

      char name[20];

      float sal;

  };

  struct emp e[10];

  int i;

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

        scanf ( "%s %f" , e[i].name, &e[i].sal );

}

Answer

Floating point formats not linked

Report Error

View answer Workspace Report Error Discuss

Subject: Programming

0 1853
Q:

We want to round off x, a Float to an Int value. The correct way to do so would be

A) Y = ( int ) ( x + 0.5 ) ; B) Y = int ( x + 0.5) ;
C) Y = ( int ) x + 0.5; D) Y = ( int ) ( ( int ) x + 0.5 )
 
Answer & Explanation Answer: A) Y = ( int ) ( x + 0.5 ) ;

Explanation:

Rounding off a value means replacing it by a nearest value that is approximately equal or smaller or greater to the given number.

 

y = (int)(x + 0.5); here x is any float value. To roundoff, we have to typecast the value of x by using (int)

 

Example:

 

#include

 

int main ()

 

{

 

  float x = 2.6;

 

  int y = (int)(x + 0.5);

 

  printf ("Result = %d\n", y );

 

  return 0;

 

}

 

Result : 3

Report Error

View Answer Report Error Discuss

Filed Under: Programming

2 5453
Q:

What would be the output of the following program?

main()

{

    int i = -3, j =2, k =0, m ;

    m = ++j && ++i || ++k ;

    Printf ( "\n%d%d%d%d", i , j , k , m );

}

Answer

-2  3  0  1

Report Error

View answer Workspace Report Error Discuss

Subject: Programming

1 1862
Q:

In the following code in which order the functions would be called?

a = ( f1 ( 23,14 ) * f2 ( 12/4) ) + f3() ;

Answer

The order may vary from compiler to compiler.


Here the multiplication will happen before the addition , but in which order the functions would be called is undefined. In an arithmetic expression the parentheses tell the compiler which operands go with which operators but do not force the compiler to evaluate everything within the parentheses first.

Report Error

View answer Workspace Report Error Discuss

Subject: Programming

0 1880
Q:

Can you suggest any other way of writing the following expression such that 30 is used only once?

a <= 20 ? b = 30 : c = 30 ;

Answer

*( ( a <= 20 ) ? &b : &c ) = 30;

Report Error

View answer Workspace Report Error Discuss

Subject: Programming

1 2058
Q:

What would be the output of the following program?

main()

{

  int i=2 ;

  printf ("\n%d%d", ++i, ++i );

}

Answer

Output may vary from compiler to compiler.


The order of evaluation of the arguments to a function call is unspecified.

Report Error

View answer Workspace Report Error Discuss

Subject: Programming

0 1769
Q:

What would be the output of the following program?

main()

{

    static int a[20];

    int i = 0;

    a[i] = i++;

    printf ("\n%d%d%d", a[0],  a[1], i);

}

Answer

0  0  1


That's what some of the compilers would give. But some other compiler may give a different answer. The reason is, when a single expression causes the same object to be modified and then inspected the behaviour is undefined.

Report Error

View answer Workspace Report Error Discuss

Subject: Programming

0 1966