24
Q:

main()

{

char s[ ] = "man";

int i;

for( i=0; s[ i ]; i++)

printf( "n%c%c%c%c", s[ i ], *(s+i), *(i+s), i[s] );

}

A) mmmm aaaa nnnn B) aaaa mmmm nnnn
C) nnnn aaaa mmmm D) None

Answer:   A) mmmm aaaa nnnn



Explanation:

s[i], *(i+s), *(s+i), i[s] are all different ways of expressing the same idea.Generally array name is the base address for that array. Here s is the base address. i is the index number/displacement from the base address. So, indirecting it with * is same as s[i]. i[s] may be surprising. But in the case of C it is same as s[i].

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 2648
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 2054
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 7619