Technical Aptitude Questions: Sample C Questions - II

Leave a Comment

16.   What will be the O/P of following code :    (“ in Turbo C “)

main()
{
printf(“%d %d”, sizeof(NULL), sizeof(“”));
}

a. 1 and 0.                               b. 0 and 1                                c. 2 and 1
d. 4 and 1                                e. None of the above

17.   What will be the O/P of following code :

main()
{
char str1[]="Hello";
char str2[]="Hello";
if(str1 == str2&& (*(str1+6)==*(str2+6)))
printf("\n Equal");
else
printf("\n unequal");
            }
a. Equal                                   b. unequal                                c. Compilation error.
d. Runtime error.                     e. None of the above.

18.    What will be the O/P of following code :

main()
{
int a, b=255,c=127;
a~=b;
c=c^(~a & b|0);\
c=c^(~(~b));
printf("%d\n",c);
            }
a. Error because of overflow;              b. 255                          c. –256                                                           
d. 127                                                  e. None of the above

19.  What will be the O/P of following code :

void func()
            {
                          printf("Testing...Done\n");
            }
            void main()
            {
                        func;
                        func();
            }
(a)Compile-Time Error            (b)Testing...Done                    (c)Testing...Done        (d)None of these

20.  A signed int bitfield 1-bit wide can only hold the values

(a)    0 and 1                        (b) 0 and -1                             (c) 0, 1 and -1              (d)None of these

21. What will be the output of the following program :
            void main()
            {
               int _;
               _=70;
               printf("%d",_);
            }
(a)Compile-Time Error            (b)Run-Time Error                  (c)70                            (d)None of these

22. What will be the output of the following program :
            #define main main()
            void main
            {
               #define END }
                printf("First"
                          "Second"
                          "Third");
            END

(a)Compile-Time Error            (b)First                                    (c)FirstSecondThird    (d)None of these
                                                    Second                                             
                                                    Third
23. What will be the output of the following program :
            void main()
            {
                        int val=1234;
                        int* ptr=&val;
                        printf("%d %d",++val,*ptr);
            }
(a)1234 1234               (b)1235 1235                           (c)1234 1235               (d)1235 1234

24. What will be the output of the following program :
            void main()
            {
                        int a=555,*ptr=&a,b=*ptr;
                        printf("%d %d %d",++a,--b,*ptr++);
            }
(a)Compile-Time Error          (b)555 554 555             (c)556 554 555                        (d)557 554 555

25. What will be the output of the following program :
            void main()
            {
                         int a[]={1,2,3,4,5,6};
                        int *ptr=a+2;
                        printf("%d %d",*++a,--*ptr);
            }
(a)Compile-Time Error            (b)2 2                                       (c)3 2                           (d)4 2

26. What will be the output of the following program :
            void main()
            {
              int matrix[2][3]={{1,2,3},{4,5,6}};
              printf("%d %d %d\n",*(*(matrix)),*(*(matrix+1)+2),*(*matrix+1));
              printf("%d %d %d",*(matrix[0]+2),*(matrix[1]+1),*(*(matrix+1)));
            }
(a)Compile-Time Error            (b)1 5 2                                    (c)1 6 2                        (d)1 6 2
                                                     6 3 4                                        3 5 4                            3 4 5

27. What will be the output of the following program :
            struct {
                         int i;
                         float f;
                       }var;
            void main()
            {
                 var.i=5;
                 var.f=9.76723;
               printf("%d %.2f",var.i,var.f);
            }
(a)Compile-Time Error            (b)5 9.76723                            (c)5 9.76                      (d)5 9.77

28.  What will be the output of the following program :
            struct values{
                         int i;
                         float f;
                   };
            void main()
            {
              struct values var={555,67.05501};
              printf("%2d %.2f",var.i,var.f);
            }
(a)Compile-Time Error            (b)55 67.05                              (c)555 67.06                (d)555 67.05

29. What will be the output of the following program :
            typedef struct {
                                     int i;
                                     float f;
                               }temp;
            temp alter(temp *ptr,int x,float y)
            {
              temp tmp=*ptr;
              printf("%d %.2f\n",tmp.i,tmp.f);
              tmp.i=x;
              tmp.f=y;
              return tmp;
            }
            void main()
            {
              temp a={65535,777.777};
              a=alter(&a,-1,666.666);
              printf("%d %.2f",a.i,a.f);
            }
(a)Compile-Time error (b)65535 777.777                    (c)65535 777.78                      (d)-1 777.78
                                                   -1 666.666                               -1 666.67                     -1 666

30. What will be the output of the following program :
            union A{
                         char ch;
                         int i;
                         float f;
                   }tempA;
            void main()
            {
              tempA.ch='A';
              tempA.i=777;
              tempA.f=12345.12345;
              printf("%d",tempA.i);          
            }
(a)Compile-Time Error            (b)12345                                  (c)Erroneous output    (d)777

0 comments:

Post a Comment