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:

Rewrite the following set of statements using conditional operators.

int a =1, b ;

if ( a > 10 )

b = 20; 

Answer

int a = 1, b , dummy;


a > 10 ? b = 20 : dummy =1;


 


Note that the following would not have worked:


a > 10 ? b = 20 : ;;


 

Report Error

View answer Workspace Report Error Discuss

Subject: Programming

3 3969
Q:

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

main()

{

    int i = 4, j = 2;

    switch(i)

    {

     case 1 :

       printf (''\n To err is human, to forgive is against company policy.");

        break;

      case j :

       printf (''\n if you have nothing to do, don't do it here.");

       break;

    }

}

Answer

Constant expression required in the second case, we cannot use j.

Report Error

View answer Workspace Report Error Discuss

Subject: Programming

0 1634
Q:

Point out the error, if any, in the while loop.

main()

{

  int i = 1;

  while ()

  {

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

     if (i >10) 

     break ;

   }

}

Answer

The condition in the while loop is a must.

Report Error

View answer Workspace Report Error Discuss

Subject: Programming

0 2600
Q:

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

main()

{

    int ( *p )() = fun;

    ( *P ) ();

}

fun ()

{

    Printf ( "\nLoud and clear" );

Answer

Here we are initalising the function pointer p to the address of the function fun(). But during this initialisation the function has not been defined. Hence an error.


To eliminate this error add the prototype of the fun() before declaration of p, as shown below:


extern int fun();    or simply  int fun();

Report Error

View answer Workspace Report Error Discuss

Subject: Programming

0 1876
Q:

What would be the output of the following program?

main()

{

    extern int fun ( float );

    int a;

    a = fun ( 3. 14 );

    printf ("%d", a);

}

int fun ( aa )

float aa ;

{

     return ( (int) aa );

}

Answer

Error occurs because we have mixed the ANSI prototype with K & R style of function definition.


When we use ANSI prototype for a function and pass a float to the function it is promoted to a double. When the function accepts this double into a float a type mismatch occurs hence the error.


The remedy for this error could be to define the function as :


int fun (float aa)


{


  ....


}

Report Error

View answer Workspace Report Error Discuss

Subject: Programming

9 8093
Q:

What is the difference between the following declarations?

extern int fun();

int fun();

Answer

There is no difference except for the fact that the first one gives a hint that the function fun() is probably in another source file.

Report Error

View answer Workspace Report Error Discuss

Subject: Programming

0 1869
Q:

What would be the output of the following program?

main()

{

  extern int i;

   i = 20;

  printf( "%d", sizeof(i) );

}

Answer

extern int i is a declaration and not a definition, hence Error occured.

Report Error

View answer Workspace Report Error Discuss

Subject: Programming

0 1815
Q:

Write a c program to copy a data of file to other file.

Answer

#include<stdio.h>
int main(){
  FILE *p,*q;
  char file1[20],file2[20];
  char ch;
  printf("\nEnter the source file name to be copied:");
  gets(file1);
  p=fopen(file1,"r");
  if(p==NULL){
      printf("cannot open %s",file1);
      exit(0);
  }
  printf("\nEnter the destination file name:");
  gets(file2);
  q=fopen(file2,"w");
  if(q==NULL){
      printf("cannot open %s",file2);
      exit(0);
  }
  while((ch=getc(p))!=EOF)
      putc(ch,q);
  printf("\nCOMPLETED");
  fclose(p);
  fclose(q);
 return 0;
}

Report Error

View answer Workspace Report Error Discuss

Subject: Programming

0 1699