Pages

Ads 468x60px

Wednesday, 6 June 2012

c aptitude question with answer volume 6


c aptitude question with answer volume 6

68.       f()
            {
            int a=2;
            f1(a++);
            }
            f1(int c)
            {
            printf("%d", c);
           
Answer:

69.       f1()
            {
            f(3);
            }
            f(int t)
            {
            switch(t);
            {
                        case 2: c=3;
                        case 3: c=4;
                        case 4: c=5;
                        case 5: c=6;
                        default: c=0;
            }
            value of c?
Answer:

70.       main ()
            {
             }
             int a;
             f1(){}
             f2(){}

    which of the functions is int a available for?
    a. all of them
    b. only f2
    c. only f1
    d. f1 and f2 only
Answer:

71.       #include<stdio.h>
                        main()
                        {
                        1+2;
                        }

        a. 3
        b. 1
        c. Error
        d. None of the above
Answer:

72.       what is an error in the following sequence of a program.

            int i1;
            switch(i1)
            {
                        case 1: goto lure;
                                    break;
                        case 2: printf("This is second choice");
                                    break;
                        default: printf("This is default choice");
            }
            void fun(void)
            {
            lure: printf("This is unconditional jump");
            }
Answer:

73.       What is the output generated by the following program ?
            #include<stdio.h>
            main()
            {
                        int a , count;
                        int func(int);
                        for (count = 1 ;count <=5;++count)
                        {
                        a = func(count);
                        printf("%d", a);
                        }
            }
            int func(int x)
            {
            int y;
            y=x*x;
            return(y);
            }

A) 1234567      b) 2516941      C)  9162514   D)   1491625
Answer:

74.       #include<stdio.h>
            void main(void)
            {
                        int oldvar=25,newvar=-25;
                        int swap(int,int);
                        swap(oldvar,newvar);
                        printf("Numbers are %d\t%d",newvar,oldvar);
            }
            int swap(int oldval,int newval)
            {
                        int tempval=oldval;
                        oldval=newval;
                        newval=tempval;
            }
Answer:

75.       #include<stdio.h>
            void main(void);
            double dbl=20.4530,d=4.5710,dblvar3;
            void main(void)
            {
            double dbln(void);
                        dblvar3=dbln();
                        printf("%.2f\t%.2f\t%.2f\n",dbl,d,dblvar3);
            }
            double dbln(void)
            {
                        double dblvar3;
                        dbl=dblvar3=4.5;
                        return(dbl+d+dblvar3);
            }

76.       What is the o/p generated by the following program ?
          main()
                {
                  int n=10;
                  int func(int);
                  printf("%d",func(n));
                }
           int func(int n)
                {
                  if(n>0)
                  return(n+func(n-2));
            }
Answer:

77.       #include<stdio.h>
            void function;
            int ivalue=100;
            main()
            {
             ivalue=50;
            function1;
            printf("ivalue in the function=",ivalue);
            printf("ivalue after the function=",ivalue);
            }
            printf("ivalue at the end of main=",ivalue);
            function()
            i-value=25;
            THIS IS ROUGH IDEA OF THE PROGRAM
   Answer:
1)i-value in the function=25;
2)i-value after the function=50;
3)i-value at the end of the main=100;

78.       main ()
             {
            char s[] = "T.C.S", *A;
             print(s);
            }
            print (char *p)
            {
            while (*p != '\0')
            {
              if (*p != ".")
                 printf ("%s", *p);
              p++;
            }
            }
    output?
    a.T.C.S
    b.TCS
    c.t  c   s
    d. none of the above
Answer:

79.       what will be the result of executing following program
            main()
            {
            char *x="new";
            char *y="dictonary";
             char *t;
             void swap (char * , char *);
             swap (x,y);
            printf("(%s, %s)",x,y);
            char *t;
            t=x;x=y;y=t;
            printf("-(%s, %s)",x,y);
            }
            void swap (char *x,char *y)
             {
             char *t;
            y=x;x=y;y=t;
             }
     a).(New,Dictionary)-(New,Dictionary)
     b).(Dictionary,New)-(New,Dictionary)
     c).(New,Dictionary)-(Dictionary,New)
     d).(Dictionary,New)-(Dictionary,New)
     e).None of the above
  
Answer:  (Ans will be b or e) check


80.         main()
            {
            funct(int n);
            {
            switch(n)
            case1:
            m=2;
            break;
            case2:
            m=5;
            break;
            case3:
            m=7;
            break;
             default:
            m=0;
            }
THIS IS ROUGH IDEA:
    (ANS:Out put is m=0)

81.       Switch (i)
            i=1;
            case 1:
           i++;
            case 2:
            ++i;
            break; 

            case 3
            --i;
a)1
b)2
c)3
d)none   
      
   Output of i after executing the program
Answer:

82.       void fn(int *a, int *b)
            {
             int *t;
            t=a;   a=b;    b=t; 
              }
            main()
            {
            int a=2, b=3;
            fn(&a,&b);
                 print the values os a and b;
             }
     what is the output---
     a. error at runtime
     b. compilation error    
     c.2 3    
     d. 3 2
Answer : out put won't swap, the same values remain.


83.       #include<stdio.h>
            int SumElement(int *,int);
            void main(void)
            {
                        int x[10];
                        int i=10;
                        for(;i;)
                        {
                                    i--;
                                    *(x+i)=i;
                        }
            printf("%d",SumElement(x,10));
            }
            int SumElement(int array[],int size)
            {
            int i=0;
            float sum=0;
            for(;i<size;i++)
                        sum+=array[i];
            return sum;
            }
Answer :


84.       #include<stdio.h>
            void main(void);
            int printf(const char*,...);
            void main(void)
            {
                        int i=100,j=10,k=20;
                        int sum;
                        float ave;
                        char myformat[]="ave=%.2f";
                        sum=i+j+k;
                        ave=sum/3.0;
                        printf(myformat,ave);
            }
Answer :


85.       #include<stdio.h>
            void main(void);
            void main(void)
            {
                        int a[10];
                        printf("%d",((a+9) + (a+1)));
            }
Answer :

86.       #include<stdio.h>
            int fn(void);
            void print(int,int(*)());
            int i=10;
            void main(void)
            {
                        int i=20;
                        print(i,fn);
            }
            void print(int i,int (*fn1)())
            {
                        printf("%d\n",(*fn1)());
            }
            int fn(void)
            {
                        return(i-=5);
            }
Answer :


87.       int bags[5]={20,5,20,3,20};
            void main(void)
            {
                        int pos=5,*next();
                        *next()=pos;
                        printf("%d %d %d",pos,*next(),bags[0]);
            }
            int *next()
            {
            int i;
            for(i=0;i<5;i++)
                        if (bags[i]==20)
                                    return(bags+i);
                        printf("Error!");
            exit(0);
            }
Answer :



88.       #include<stdio.h>
            void main(void);
            int newval(int);
            void main(void)
            {
                        int ia[]={12,24,45,0},i,sum=0;
                        for(i=0;ia[i];i++)
                        {
                        sum+=newval(ia[i]);
                        }
            printf("Sum= %d",sum);
            }

            int newval(int x)
            {
            static int div=1;
            return(x/div++);
            }
Answer :


89.       #include<stdio.h>
            void main(void);
            void main(void)
            {
            void pa(int *a,int n);
            int arr[5]={5,4,3,2,1};
            pa(arr,5);
            }
            void pa(int *a,int n)
            {
            int i;
            for(i=0;i<n;i++)
            printf("%d\n",*(a++)+i);
            }
Answer :


90.       #include<stdio.h>
            void main(void);
            void print(void);
            void main(void)
            {
                        print();
            }
            void f1(void)
            {
            printf("\nf1():");
            }
Answer :

91.       What will be result of the following program
             main()
            {
            void f(int,int);
             int i=10;
             f(i,i++);
            }
            void f(int i,int j)
            {
            if(i>50)
            return;
            i+=j;
            f(i,j);
            printf("%d,",i);
             }
      a).85,53,32,21
      b)10,11,21,32,53
      c)21,32,53,85
      d)32,21,11,10
      e)none of the above
      Answer :  e)

92.       #include "6.c"
            void print(void)
            {
            extern void f1(void);
            f1();
            }
            static void f1(void)
            {
            printf("\n static f1().");
            }
Answer :


93.       #include<stdio.h>
            void main(void);
            static int i=50;
            int print(int i);
            void main(void)
            {
            static int i=100;
            while(print(i))
            {
                        printf("%d\n",i);
                        i--;
            }
            }
            int print(int x)
            {
            static int i=2;
            return(i--);
            }
Answer :

94.       #include<stdio.h>
            void main(void);
            const int k=100;
            void main(void)
            {
                        int a[100],sum=0;
                        for(k=0;k<100;k++)
                        *(a+k)=k;
                        sum+=a[--k];
                        printf("%d",sum);
            }
Answer :



95.       What is the output of the following program
            main ()
              {
            unsigned int i;

             for (i = 10; i >= 0; i--)
             printf ("%d", i);
             }
            a) prints numbers 10 - 0         
            b) prints nos 10 - 1
            c) goes into infinite loop
Answer :

96.       main ()
            {
             char *name = "name";
             change (name);
              printf ("%s", name);
             }
             change (char *name)
             {
             char *nm = "newname";
             name = nm;
             }
    what is the output?
            a) name           
            b) newname    
            c) name = nm not valid
            d) function call invalid
Answer :

97.       main()
             {
            int n = 3;
            f(n);
            printf("MAIN");
            }
            void f(int n)
             {
            printf("F");
            if ( n != 0 )
            f(n-1);
            }
What is the output of the above code?
Answer :  FFFF



INCREMENT & DECREMENT OPERATORS

98.       void main()
            {
            int i=7;
            printf("%d",i++*i++);
            }

Answer: 56

99.       What is the output of the following ?
            main()
            {
            int i;
            i=1;
            i=i+2*i++;
            printf(%d,i);
Answer :  4


 100.    main()
            {
                int i=2;
            printf("%old %old %old %old ",i, i++,i--,i++);
            }

  a. ol2 ol2  ol3 ol2
  b. ol3 ol2  ol3 ol2
  c. 2ld 2ld  3ld 2ld
  d. 3ld 2ld  3ld 2ld
Answer :

101.     what is o/p
              main()
            {
            int i=3;
            while(i--)
            {
             int i=100
              i--;
              printf("%d..",i);
             }
            }
  a) infinite loop
  b) error
  c) 99..99..99..99
  d) 3..22..1..
Answer : 




0 comments:

Post a Comment

Total Pageviews