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:

How would you find the length of each string in the following Program?

main()

{

    char *str[] = { "Frogs", "Do", "Not" , "Die" , "They" , "Croak!"};

    printf ("%d%d", sizeof (str), sizeof (str[0]));

}

Answer

main()


{


   char *str[] = { "Frogs", "Do", "Not", "Die." , "They", "Croak!" };


   int i;


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


         printf ("\n%s%d", str[i], strlen( str[i]));


}

Report Error

View answer Workspace Report Error Discuss

Subject: Programming

1 1751
Q:

What would be the output of the following program?

main()

{

     char ch ='A';

      printf ("%d%d", sizeof (ch), sizeof ('A'));

}

Answer

1   2

Report Error

View answer Workspace Report Error Discuss

Subject: Programming

0 2293
Q:

What would be the output of the following program, if the array beigns at address 65486?

main()

{

    int arr[] = {12,14,15,23,45};

    printf ("%u %u", arr, &arr);

}

Answer

65486  65486

Report Error

View answer Workspace Report Error Discuss

Subject: Programming

0 1755
Q:

What would be the output of the following program?

main()

{

    char a[] = "Visual C++";

    char *b = "Visual C++";

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

    printf ("\n%d %d", sizeof (*a), sizeof (*b));

Answer

11  2


 1   1

Report Error

View answer Workspace Report Error Discuss

Subject: Programming

1 1771
Q:

How would you obtain segment and offset addresses from a far address of a memory location?

Answer

#include "dos.h"


main()


{


    Char far *scr = ( char far *) 0xB8000000;


    Char *seg, *off;


    Seg = (char *) FP_SEG ( scr );


    Off = ( char *) FP_OFF ( scr );


}


 

Report Error

View answer Workspace Report Error Discuss

Subject: Programming

0 1988
Q:

How would you eliminate the warning generated on complaining the following program?

main()

{

  char far *scr;

  scr = 0xB8000000;

  *scr = 'A';

}

Answer

Use the typecast scr = (char far *) 0xB8000000;

Report Error

View answer Workspace Report Error Discuss

Subject: Programming

0 1614
Q:

Would the following program compile?

main()

{

    int a = 10, *j;

    void *k;

    J = k = &a;

    J++;

    k++;

   printf ("\n%u %u", j, k);

}

Answer

An error would be reported in the statement k++ since arithmetic on void pointers is not permitted unless the void pointer is appropriately typecasted.

Report Error

View answer Workspace Report Error Discuss

Subject: Programming

0 2306
Q:

What would be the output of the following program assuming that the array beigns at location 1002?

main()

{

   int a[3][4] = {

                            1 , 2 , 3 , 4

                            5,  6 , 7, 8

                            9, 10 , 11, 12

                       };

    Printf ("\n%u %u %u", a[0] + 1, *( a[0] + 1), *( *(a + 0) + 1) );

}

Answer

1004  2  2

Report Error

View answer Workspace Report Error Discuss

Subject: Programming

1 1846