2
Q:

If the following program (myprog) is run from the command line as 

myprog 1 2 3 

what would be the output?

main(int argc, char *argv[])

{

    int i, j = 0;

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

           j = j + atoi ( argv[i]);

    printf ("%d", j);

}

A) 123 B) 6
C) Error D) "123"

Answer:   B) 6



Explanation:

When atoi() tries to convert argv[0] to a number it cannot do so (argv[0] being a file name) and hence returns a zero.

Subject: Programming
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 2055
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 3333
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 1816
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 1918
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 2519
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 1745
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 7621
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 1777