8
Q:

enum colors {BLACK,BLUE,GREEN}

main()

{

printf( "%d..%d..%d", BLACK, BLUE, GREEN );

return(1);

}

A) 1..2..3 B) 0..1..2
C) 1..1..1 D) 0..0..0

Answer:   B) 0..1..2



Explanation:

enum assigns numbers starting from 0, if not explicitly defined.

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 4619
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 1739
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 2745
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 1984
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 8494
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 2001
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 2054
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 1782