VIRTUOSO

 

–Sharp Thoughts–

 

 

 

BYTE A BUG

 

 

 

 

[C – DEBUGGING]

 

     1.  void main()

          {

            static int a[10],i;

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

                        {

                                    a[i]=0;

                        printf("%d",a[i]);

                        }

          }

          a) 00000      b) 000000000    c) infinite 0's   d) Run time Error

 

 

   2.   void abc();

int *ptr;

void main()

{

            int i,*p=&i;

            abc();

}

void  abc()

{

            int i=0;

            ptr=&i;

            ptr++;  *ptr=0;

            printf("\nHAI %d",i);

}

            a) HAI 0     b) HAI 1     c) No output    d) Error

 

 

    3.      int a=3,*ptr=&a,aaa=100;

void main()

{

            int *p=&aaa;

            --p;      *p=0;

            printf("%d %d %d",*p,*ptr,a);

}

a) 0 0 0     b) 0 3 3    c) 0 0 3     d) Error

 

 

    4.   void main()

         {

            union a

            {

                        int b;

 

 

                        struct c

                        {

                                    char i,j;

                        }ch;

            };

union a obj1;

            obj1.b=255;

            printf("%d %d",obj1.ch.i,obj1.ch.j);

     }

     a) 0 255    b) 255 0    c) -1 0    d) Error

 

 

  5 .   main()

{

            float f=9.99;     char d[10]="'wrong'";

            printf("\t%d",printf("\n\\float!!!"));

            printf("\t%d",printf("\n%f",f));

            printf("\t%d",printf("\n%s",d));

}

 

            a)  \float!!!                    10                    b)  12               \float!!!

      9.990000               9                           4                 9.990000

      'wrong'   8                                           8  'wrong'

           

c)  \float!!!                    12                    d)  None of the above

     9.990000                4 

     'wrong'   8

 

 

    6.     #define sqr(x) ++x * ++x

void main()

{

                        int i=3,t;

            t=++i * ++i;     i-=2;

            printf("%d %d",sqr(i),t);

}

 

            a) 25  25    b) 9  9     c) 20 25    d) 25 9

  

    7.     void main()

{

            printf("HELLO\xD");

            printf("KCT");

}

            a) HELLO\xDKCT     b) HELLODKCT    c) HELLO13KCT    d) KCTLO

 

    8.  void main(void)

{

            char ch[10],*ch1;

            printf("%x %x\n",ch,&ch);

                        printf("%x %x",ch1,&ch1);

}

 

            //Assume A,B,C,D are different addresses

           a) A B      b) A A       c)  A A      d) A B

               C D          C C             C D          C C

 

 

    9.     void main()

{

                        int i,j;

for(i=1,j=1;i<=5,j<=10;i++,j++)

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

}

 

            a)  Prints natural numbers twice till 5                  b) Prints natural numbers twice till 10

c)  Prints natural numbers till 5               d)  Error



 

    10.   void main()

{

            int i=10,j=20;

            printf("%d %d %d %d;");         printf("%d; %d");

}

 

            a)  20 10 0 344;20;20              b)  junk values

c)  20 10 20 10; 20; 10            d) 20 20 20 20;20;20



 

    11.   main()

{

                        int i;      char a[]="\0";

            if(printf("%s",a))            printf("null is null");

            else      printf("null is not null");

            }

 

a)  null is null                 b) Compile error:Non portable pointer conversion

c) null is not null            d) Compile error:Invalid assignment to ‘a’

 

 

 

 

    12.   void main()

{

            char ch[20]="abcdefghijklm";

            printf("\n%5.2s",ch);

}

 

            a)     abcd         b) abcdefghijklm           c)      abcdefghijklm      d)      ab

 

 

    13.   main()

{

      int i=1,j=1;

      for(;j;printf("%d %d\n",i,j))

                        j=i++<=5;

}

 

            a) 1 1               b) 2 1               c) 2 1               d) Error

    2 1                   3 1                   3 1

    3 1                   4 1                   4 1

    4 1                   5 1                   5 1

    5 0                   6 0                   6 1

                                                    7 0

 

    14.    /* If this program is executed in Borland C++, Then what will be the output? */

           void main()

          {

char *a;

char *b,*c;

clrscr();

strcpy(a,"123");

b=_fstrdup(a);

strcpy(c,a);

printf("%s\n%s",b,c);

printf("%s",4);

          }

 

–––––––––––––––––––––––––––––––––––––––––––––––

                                                          

  15.   /* What does the program do? */

            main()

           {

int kb;

while(1)

{

if(inportb(0x60)==68)              break;

kb=peek(0x0040,0x001A);

poke(0x0040,0x001C,kb);

}

}

 

            –––––––––––––––––––––––––––––––––––––––––––––––

 

 

    16.   void main()

{

 float x;   double y = 1.5e-38;

 x = y;

 printf("\n\nStatus 87 after  error: %X\n", _status87());

}

 

            a)  Error             b)  20             c)  1.5e-38                   d)  30

 

 

    17.   extern unsigned _stklen = 543210U;

void main()

{

            printf("\nThe stack length is %u\n", _stklen);

}

 

            a) 18922          b) 23678          c) 1      d) 543210

 

 

    18.   main()

{

            int a(int),n=10;

            a(n);

}

int a(int n)

{

            int i;

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

            a(n-i);

                        printf("\nKCT");

}

 

            a)   KCT          b)   KCTKCTKCTKCTKCTKCTKCTKCTKCTKCT

c)   infinite loop d)   KCTKCT...........

 

 

    19.   char src[15] = "rtiaingn s";

char target[15];

 

void main()

{

swab(src,target,strlen(src));

printf    ("This is target: %s\n", src);

}

           What is the output of the above program?

          

–––––––––––––––––––––––––––––––––––––––––––––––

 

 

    20.   int sort(const void *a, const void *b);        char arr[5][4] = {"cat", "cart", "cab", "cap", "can" };

void main()

{

            int  i;

 qsort((void *)arr, 5, sizeof(arr[0]), sort);

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

      printf("%s\n",arr[i]);

}

int sort(const void *p, const void *q)

{

 return(strcmp((char *)p,(char *)q));

}         

 

           a) cab                b) cab              c) cab               d) None of the above

   can                    can                   can

   cap                    cap                   cap

   cartcat               cart                  car

   cat                     cat                    cat

 

 

    21.  main()

{

            char a=0xAA;

            int b;

            b=(int)a;

            b=b>>4;

            printf("%x",b);

}

 

            a) fffa               b) error            c) 762e                        d) d5ec

 

 

    22.   enum mode = {green,red,orange,blue,white};

main ()

{

            green = green + 1;

            printf("%d,%d",green,red );

}

 

            a)  1,1                                                              b)  0,1             

c)  No output, error in compilation                    d)  None of the above

 

 

   23.             char *c[] ={

            "FILE",

            "EDIT",

            "SEARCH",

            "COMPILE",

            };

char **cp[] = {c+3,c+2,c+1,c},***cpp = cp;

main()

{

            printf("%s", **cpp);

            printf("%s"< *--*++cpp+3);

            printf("%s", *cpp[-2]+3);

            printf("%s\n",cpp[-1][-1]+1);

                        }

 

            a) SEARCHFILEEDITCOMPILE                   b) SEARCHCOMPILEEDIT

c) SEARCHEPILEDIT                                    d) None of the above

 

 

    24.   main()

{

int a=1; b=2; c=3; *ptr;

ptr        =&c;

a=c /*ptr;

b=c;

printf("a=%d b=%d",a,b);

}

 

            a) a=1 b=3                   b)  a=3 b=3                  c)  3     2          d) Error

 

 

   25.             main()

{

char *p="Virtuoso%s";

printf(p);

}

 

            a) Virtuoso%s                                      b) Virtuoso

c) VirtuosoVirtuoso%s             d) Blank Screen

    26.   main()

{

printf("%d",call());

}

call()

{

_AH=1;

return;

}

 

            a) 0                  b) 1                  c) <junk>               d) 256

 

 

    27.   # define loop while(1)

main()

{

loop;    printf("DONE");

}

 

            a) DONE         b) DONE......     c) infinite loop d) Error

 

 

    28.   void main()

{

 float a,b,c,d,d1,d2;

             d=sqrt(b*b-4*a*c);

 scanf(“%d%d%d”,a,b,c);

 d1=(-b+d)/(2*a);    d2=(-b-d)/(2*a);

 printf(“%d %d”,d1,d2);

}

 

If 1,1,1 are inputs, then what will be the output?

 

a) Compiler Error         b) Linker Error c) Domain Error           d) None of the above

 

 

    29.   void main()

            {

            typedef struct student

            {

char name[20];

                        float sal;

                        int no;

                        void input()

                        {  printf("%d",sal);  }

   }Welcome;

   Welcome *p;

   Welcome come={"Kumaraguru College Of Technology",1888.98,23};

   p=&come;

   printf("%s %f %d\n",come.name,come.sal,come.no);

   printf("%s %f %d",p[1].name,0[p].sal,p->no);

}

 

            a)  Kumaraguru College Of Technology 1888.98 23

     Kumaraguru College Of Technology 1888.98 23

b)  Kumaraguru College Of Technology 1888.98 23

     <junk> <junk> 23

c)  Kumaraguru College Of Technology 1888.979980 23

     <junk> <junk> 23

d)  Kumaraguru College Of Technology 1888.979980 23

     1888.979980 23

 

 

    30.   void main() 

{

            int a,b;

 (char)(a)=a >> b << ~a;

 printf(  “d %d",a,b);

}

 

            If the junk values of a and b are X & Y respectively, Then what will be the output ?

 

a) X Y              b) Y X             c) 0 X              d) None of the above

 

 

    31.   void main()

{

 int a=2,b=7,c;

 c= b <<  a;

 b=c*(b*(++a)--);

 a=a >> b;

 printf("%c",b);

}

 

            a) R                  b) k                  c) L               d) <junk>

 

 

    32.   void main()

{

            FILE *fp;   char ch;

 fp=fopen("C:\\temp.txt","r");

 if(fp==NULL)    printf("ERROR");

    while(ch!=EOF)

   {

            ch=getc(fp);

            printf("%c",ch);

   }

   fclose(fp);

   unlink("C:\\temp.txt");

}

 

            a) Displays the content of the file and frees its associated memory

b) Displays the content of the file and deallocates its reference

c) Displays the content of the file and deletes the file

d) Error

 

 

    33.   void main()

{

                        printf("\n%d",3.00);

}

 

            a) 3                  b) 3.00             c) 3.000000                 d) Depends on the compiler

 

 

    34.   void main()

{

   char *name;

   name = getpass("Enter The String:");

   cprintf("String:%s\r\n",name);

}

 

            a) Gets the system password and compares with the supplied password

b) Gets a password from the user by echoing * and displays it

c) Gets a password from the user by without echoing it and displays it

d) Error

 

 

   35. #define MAX(x,y) ((x)>(y))?(x):(y)

             main()

{

int x=5,y=5;

printf("maximum is %d",MAX(++x,++y));

            }

 

            a) maximum is 7            b) maximum is 5           c) maximum is 6            d) none of the above

 

 

    36.   void main()

{

   char ch1,ch2;

   if (ch1 = getch()) ungetch(ch1);

   ch2=getch();

   printf("%c",ch2);

}

 

            If the input is a & b,Then what is the output?

 

a) a                  b) b                  c) Junk value                d) Error

 

 

 37.    int i=1;

  void subroutine(jmp_buf);

              void main()

  {

                          int value=0;

  jmp_buf jump;

  value = setjmp(jump);

  printf("Longjmp with value %d\n", value);

   if (!i) exit(0);

   printf("About to call subroutine ... \n");

   subroutine(jump);

}

void subroutine(jmp_buf jumper)

{

   longjmp(jumper,i--);

}

 

            a) Longjmp with value 0                                    b) Longjmp with value 0

    About to call subroutine ...                             About to call subroutine ...

    Longjmp with value 0                                        Longjmp with value 1

   About to call subroutine ...                                 About to call subroutine ...

c) Infinite Loop                                     d) None of the above

 

 

    38.   void main()

{

            int i=100,j=20;

            i++=j;

            i*=j;

            printf("%d\t%d\n",i,j);

}

 

            a) 400,20         b) 2420,20       c) 2020,20       d) Lvalue required

    39.   void main()

{

   #define STDOUT 1

   int nul, oldstdout;

   char msg[] = "VIRTUOSO";

   nul = open("virtuoso.txt",O_CREAT | O_RDWR,S_IREAD | S_IWRITE);

   oldstdout = dup(STDOUT);

   dup2(nul, STDOUT);

   close(nul);

   write(STDOUT, msg, strlen(msg));

   dup2(oldstdout, STDOUT);

   close(oldstdout);

}

 

            a) Redirects to the standard output given file

b) Creates a duplicate handle for controlling the display on the screen

c) Duplicates the standard output and store it in the given file

d) Error

 

 

    40.   void main()

{

printf("%d",MAXSHORT);

}

 

            a) 255              b) 16383          c) 32767          d) 65535

 

 

     41.   void main()

{

 cprintf("KUMARAGURU COLLEGE OF TECHNOLOGY\r\n");

 cprintf("CSE DEPARTMENT\r\nVIRTUOSO\r\n");

 gotoxy(1, 3);

 insline();

}

            a) VIRTUOSORTMENTLEGE OF TECHNOLOGY

b) KUMARAGURU COLLEGE OF TECHNOLOGY

           

   CSE DEPARTMENT

   VIRTUOSO

c) KUM

   ARAGURU COLLEGE OF TECHNOLOGY

   CSE DEPARTMENT

   VIRTUOSO

d) Error

 

 

    42.   main()

{

 int rows=3,colums=4, i,j,k;

 int a[rows][colums]={1,2,3,4,5,6,7,8,9,10,11,12};

 i=j=k=99;

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

 for(j=0;j<colums;j++)

            if(a[k][j]<k)

 k=a[i][j];

 printf("%d\n",k);

}

 

a) 10                b) –7                c) 256              d) Error

 

 

    43. void main()

{

char as[]="\\0\0";          int i=0;

do{

            switch(as[i++])

{

case '\\': printf("A");

case 0: printf("B");

default: printf("C");break;

}

     }while(i<3);

}

 

            a) ABCBCC                b) CCBC                     c) ABCCBC                d) ABCBCC

 

 

    44.   typedef static int si;

void main()

{

            si i=2,j=1,k=0,t;

            t=++k||--j&&i--;

            printf("%d %d %d %d",i,j,k,t);

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

}

            a) 1 0 1 1 2                  b) 2 1 1 0 2                  c) 2 1 1 1 1                  d) Error

 

 

    45.   double dbl=20.4530,d=4.5710,dblvar3;

void main()       {

            double dbln(void);

            dblvar3=dbln();

                        printf("%.2f,%.2f,%.2f\n",dbl,d,dblvar3);

}

double dbln(void)

{

            double dblvar3;

            dbl=dblvar3=4.5;

            return(dbl+d+dblvar3);

}

 

            a) 4.50,4.57,13.57                   b) 4.50,4.57,9.07

c) 4.50,4.57,13.60                   d) 4.50,4.60,13.60

 

 

     46.  struct ITEM {

                 int key, value;

            };

void additem(struct ITEM *itemptr)

{

   assert(itemptr == NULL);

}

void main()

{

   struct ITEM *ptr;

   ptr->key=1;

   ptr->value=1;

   additem(ptr);

}         

 

            a) 1                                                      b) Add an item to the given list

c) Checks whether the given item is in the list or not                   d) Error

 

 

    47.   typedef struct a

{

            int x;

            aType *b;

}aType;

void main()       {

            aType gg;

            gg.x=10;

            gg.b=NULL;

            printf("%d %u",gg.x,gg.b);

}

            a) 10 0             b) 0 10             c) 10           d) Compiler error

 

 

    48.   main()

{

            int i,n;

            char *str="girl";

            n=strlen(str);

            *str=str[n];

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

            {

            printf("%s;",str);

                        str++;

            }

}

 

            a) ;irl;rl;l;      b) girl;irl;rl;l;          c) Runtime error:Null pointer assignment      d) junk values

 

 

    49.   void main(void)

{

            char ************a;

                        printf("\n%u %d", a, sizeof(char huge*near*));

}

 

            a) <junk> 4                  b)   4                c) 0 2               d) compiler error

 

 

    50.   void main()

{

   char name[13];

   printf("%s", tmpnam(name));

 }

 

   a) Displays a name which can be used for as a variable name in the program without any conflict

 

   b) Displays a name which can be used for as a Temporary value of a string variable in

        the program without any conflict

 

c) Displays a name which can be used for as a Temporary name of a file in the current directory                 

    without any conflict

 

    d) Linking error:Undefined symbol _tmpname in module c:\fn.c

 

 

 

*********************************