Home Company Questions Aditi Interview Questions Aditi Interview Questions - 5

Login Form




Aditi Interview Questions - 5 Print E-mail

1. What would be the output of the following program.
                        main()
                        {
                            int a[5]={2,3};
                            printf("\n %d %d %d",a[2],a[3],a[4]);
                        }

(a) garbage value
(b) 2   3   3
(c) 3   2   2
(d) 0   0   0


2. What would be the output of the following program.

                        #include<stdio.h>
                        main()
                        {
                            char str[5]="fast";
                            static char *ptr_to_array = str;
                            printf("%s",ptr_to_array);
                        }

(a) Compilation will only give a warning but will proceed to execute & will display "fast"
(b) display "fast" on screen
(c) will give a compilation error
(d) none of the above


3. What would be the output of the following program.
                        main()
                        {
                            int i=10;
                            fn(i);
                            printf("%d",i);
                        }
                        fn(int i)
                        {
                            return ++i;
                        }

(a) 10
(b) 11
(c)12
(d) Compilation error


4. What would be the output of the following program.
                        main()
                        {
                            const int x=get();
                            printf("%d",x);
                        }
                        get()
                        {
                            return(20);
                        }

(a) 20
(b) garbage value
(c) error
(d) 0


5. What would be the output of the following program.
                        main()
                        {
                            int num,*p;
                            num=5;
                            p=#
                            printf("%d",*p);
                        }

(a) 6
(b) 5
(c) junk value
(d) compilation error


6. Can the following piece of code be executed?

                        int main(void)
                        {
                            char strA[10]="compile",strB[10];
                            my_strcpy(strB,strA);
                            puts(strB);
                        }
                        char * my_strcpy(char *destination,char *source)
                        {
                            char *p=destination;
                            while(*source!='\0')
                            {
                                *p++=*source++;
                            }
                            *p='\0';
                            return destination;
                        }

(a) Compilation will only give a warning but will proceed to execute & will display "compile"
(b) The compilation error char *(char *,char *) differs in levels of indirection from 'int()' will occur
(c) Yes & it will print compile on the screen
(d) None of the above


7. What would be the output of the following program.
                        #define CUBE(x) (x*x*x)
                        main()
                        {
                            int a,b=3;
                            a=CUBE(b++);
                            printf("\n %d %d",a,b);
                        }
(a) 64    4
(b) 27    4
(c) 27    6
(d) 64    6


8. What would be the output of the following program.
                        main()
                        {
                            int a[3]={2,3,4};
                            char *p;
                            p=a;
                            p=(char *)((int *)p+1);
                            printf("%d",p);
                        }

(a) 2
(b) 0
(c) junk value
(d) 3


9. Pointout the error, if any, in the for loop
                        main()
                        {
                            int l=1;
                            for(;;)
                            {
                                printf("%d",l++);
                                if(l>10)
                                     break;
                            }
                        }

(a) The condition in the for loop is a must
(b) The two semicolons should be dropped
(c) The for loop should be replaced by awhile loop
(d) No error


10. What would be the output of the following program.
                        main()
                        {
                             int a,b;
                            a=sumdig(123);
                            b=sumdig(123);
                            printf("%d %d",a,b);
                        }
                        sumdig(int n)
                        {
                            static int s=0;
                            int d;
                            if(n!=0)
                            {
                                d=n%10;
                                n=(n-d)/10;
                                s=s+d;
                                sumdig(n);
                            }
                            else   return(s);
                        }
(a) 12    6
(b) 6    12
(c) 3    15
(d) error