Company: Amazon Development Centre India

AMAZON Previous Years Questions

1. Two tables emp (empid, name, deptid, sal) and dept (deptid, deptname) are there. Write a query which displays empname, corresponding dept name and also display those employee names that do not belong to any dept.

2. Write prefix and post fix notation for

(a+b)*c-(d+e)^(f-g)

3. Write program to swap 2 variables without using extra memory.

4. Find the output for the following C program fn f(x)

{

if(x<=0) return; else f(x-1)+x; } 5. Find the output for the following C program main() { intx=2,y=6,z=6; x=y=z; printf(%d",x) } 6. Copy a file form one host "amazon.chennai" to another host "amazon.bbsr" 7. You want to find out the value of the last element of an array. You write the following code. What will happen when you compile and run it.? public class MyAr { public static void main(String argv[]) { int[] i = new int[5]; System.out.println (i[5]); } } 1) An error at compile time 2) An error at run time 3) The value 0 will be output 4) The string "null" will be output. 8. Find the second largest element in an array with minimum no of comparisons and give the minimum no of comparisons needed on an array of size N to do the same. 9. Write a program to remove duplicates from a sorted array. 10. In C, if you pass an array as an argument to a function, what actually gets passed? A. Value of elements in array B. First element of the array C. Base address of the array D. Address of the last element of array Ans-C 11. What will be the output of the program? #include

int main()

{

viod fun( int, int[]);

int arr[] = {1, 2, 3, 4};

int i;

fun (4, arr);

for (i=0; i<4; i++) printf(“%d,”, arr[i]); return 0; } void fun(int n, int arr[]) { int *p=0; int i=0; while(i++ < n) p = &arr[i]; *p=0; } A. 2, 3, 4, 5 B. 1, 2, 3, 4 C. 0, 1, 2, 3 D. 3, 2, 1 0 Ans-B 12. What will be the output of the program if the array begins 1200 in memory? #include

int main()

{

Int arr[]={2, 3, 4, 1, 6};

printf(“%u, %u, %un”, arr, &arr[0], &arr);

return 0;

}

A. 1200, 1202, 1204

B. 1200, 1200, 1200

C. 1200, 1204, 1208

D. 1200, 1202, 1200

Ans-B

13. Which of the following statements are correct about an array?

1: The array int num [26]; can store 26 elements.

2: The expression num [1] designates the very first element in the array.

3: It is necessary to initialize the array at the time of declaration.

4: The declaration num [SIZE] is allowed if SIZE is a macro.

A. 1

B. 1,4

C. 2,3

D. 2,4

Ans-B

14. Which of the following function is used to find the first occurrence of a given string in another string?

A. strchr()

B. strrchr()

C. strstr()

D. strnset()

Ans-C

15. Which of the following function is correct that finds the length of a string?

A. –

int xstrlen(char *s)

{

int length=0:

while(*s!=’’)

{ length++; s++; }

}

B –

int xsrrlen(char s)

{

int length=0;

while(*s!=’’)

length++; s++;

return (length);

}

C-

int xstrlen(char *s)

{

int length=0;

while(*s!=’’)

length++

return (length);

}

Ans-A

16. What will be the output of the program in 16-bit platform (Turbo C under DOS)?

#include

Int main()

{

Printf(“%d, %d, %d”, sizeof(3.0f), sizeof(‘3’)), sizeof(3.0);

Return 0;

}

A. 8, 1, 4

B. 4, 2, 8

C. 4, 2, 4

D. 10, 3, 4

Ans-B

17. Which of the following statements are correct ?

1: A string is a collection of characters terminated by ‘’.

2: The format specifier %s is used to print a string.

3: The length of the string can be obtained by strlen().

4: The pointer CANNOT work on string.

A. A, B

B. A, B, C

C. B, D

D. C, D

Ans-B

18. Point out the error in the program?

#incluse

int main()

{

struct emp

{

char name[20];

float sal;

};

struct emp e[10];

int i;

for(i=0; i<=9; i++) scanf(“%s %f”’ e[i].name, &e[i].sal); return 0; } A. Error: invalid structure member B. Error: Floating point formats not linked C. No error D. None of above Ans-B 19. What is the similarity between a structure, union and enumeration? A. All of them let you define new values B. All of them let you define new data types C. All of them let you define new pointers D. All of them let you define new structures Ans-B 20. What will be the output of the program ? #include

int main()

{

enum days {MON=-1, TUE, WED=6, THU, FRI, SAT};

printf(“%d, %d, %d, %d, %d, %dn”, MON, TUE, WED, THU, FRI, SAT);

return 0;

}

A. -1, 0, 1, 2, 3, 4

B. -1, 2, 6, 3, 4, 5

C. -1, 0, 6, 2, 3, 4

D. -1, 0, 6, 7, 8, 9

Ans-D

21. What will be the output of the program ?

#include

struct course

{

int courseno;

char coursename[25];

};

int main()

{

struct course c[] = { {102, “Java”},

{ 103, “PHP”},

{104, “DotNet”} };

printf(“%d”, c[1].courseno);

printf(“%sm”, (*(c+2)).coursename);

return 0;

}

A. 103 Dotnet

B. 102 Java

C. 103 PHP

D. 104 DotNet

Ans-A

22. In which stage the following code

#include

gets replaced by the contents of the file stdio.h

A. During editing

B. During linking

C. During execution

D. During preprocessing

Ans-D

23. Point out the error in the program

#incluse

int main()

{

int I;

#if A

printf(“Enter any number:”);

scanf(“%d”, &i);

#elif B

printf(“ The number is odd”);

return 0;

}

A. Error: unexpected end of file because there is no matching #endif

B. The number is odd

C. Garbage values

D. None of above

Ans-A

24. What are the different types of real data type in C?

A. float, double

B. short int, double, long int

C. float, double, long double

D. double, long int, float

Ans-C

25. Which statement will you add in the following program to work it correctly?

#include

Int main()

{

printf(“%fn”, lof(36.0));

return 0;

}

A. #include

B. #include

C. #include

D. #include

Ans-B

26. What do the following declaration signify?

int *ptr[30];

A. ptr is a pointer to an array of 30 integer pointers.

B. ptr is a array of 30 pointers to integers.

C. ptr is a array of 30 integer pointers.

D. ptr is a array 30 pointers.

Ans-B

27. What is x in the following program?

#incluse

int main()

{

typedef char (*(*arrfptr[3])())[10];

arrfptr x;

return 0;

}

A. x is a pointer

B. x is an array of three pointer

C. x is an array of three function pointers

D. Error in x declaration

Ans-C

28. In the following code snippet can we declare a new typedef named ptr even though struct employee has not been completely declared while using typedef?

typedef struct employee *ptr;

struct employee

{

char name[20];

int age;

ptr next;

}

A. Yes

B. No

Ans-A

29. What will be the output of the program?

#include

int i;

int fun1(int);

int fun2(int);

int main()

{

extern int J;

int i=3;

fun1(i);

printf(“%d,”, i);

fun2 (i);

printf(“%d”, i);

return 0;

}

int fun1(int j)

{

printf(“%d,”, ++j);

return 0;

}

int fun2(int i)

{

printf(“%d,”, ++i);

return );

}

intj=1;

A. 3, 4, 4, 3

B. 4, 3, 4, 3

C. 3, 3, 4, 4

D. 3, 4, 3, 4

Ans-B

30.Given a binary search tree,print out the nodes of the tree according to post order traversal.

4

/

2 5

/

1 3

a)3,2,1,5,4. b)1,2,3,4,5. c)1,3,2,5,4. d)5,3,1,2,4.

Aptitude

1.Predict the output or error(s) for the following:

1.

void main()

{

int const * p=5;

printf(“%d”,++(*p));

}

2.

main()

{

char s[]=“man”;

int i:

for(i=0;s[i];i++)

print[“n%c%c%c%c”,s[i],*(s+i),*(i+s),i[s]);

}

3.

main()

{

static int var = 5;

printf(“%d”, var–);

if(var)

main();

}

4

main()

{

int c[] = {2,8,3,4,4,6.7,5};

int j,*p=c,*q=c;

for(j=0;j<5;j++) { printf(“%d”,*c); ++q; } for(j+0;j<5;j++){ printf(“%d”,*p); ++p; } } 5. main() { extern int i: i=20; printf(“%d”,i); } 2. What are the files which are automatically opened when a C file is executed? 3. What will be the position of the file marker? a: fseek(ptr,0,SEEK_SET); b: fseek(ptr,0,SEEK_CUR); 4. What is the problem with the following code segment? while ((fgets(receiving array,50,file_ptr)) != EOF) 5. Predict the output or error(s) main() { int a[2][3][2] = {{{2,4},{7,8},{3,4}},{{2,2},{2,3},{3,4}}}; printf(“%u %u %u %dn”,a,*a,**a,***a); printf(“%u %u %u %dn”,a+1,*a+1,**a+1,***a+1); } 6. Predict the output or error(s) main() { static int a[] = {0,1,2,3,4}; int *p[] = {a,a+1,a+2,a+3,a+4}; int **ptr = p; ptr++; printf(“n %d %d %d”, ptr-p, *ptr-a, **ptr); *ptr++; printf(“n %d %d %d”, ptr-p, *ptr-a, **ptr); *++ptr; printf(“n %d %d %d”,m ptr-p, *ptr-a, **ptr); ++*ptr; printf(“n %d %d %d”, ptr-p, *ptr-a, **ptr); } 7. In the following pgm add a stmt in the function fun such that the address of 'a' gets stored in 'j'. main(){ int *j; void fun(int **); fun(&j); } void fun(int**k){ int a=0; /*add a stmt here*/ } Ans- *k = &a 8. What are the following notations of defining functions known as? I. int abc(int a,float b) { /*some code */ } II. int abc(a,b) int a; floatb; { /*some code*/ } Ans i. ANSI C notation ii. Kernighan & Ritche notation 9. Is the following statement a declaration/definition. Find what does it mean? int (*x)[10]; Ans- Definition-x is a pointer to array of(size 10) integers. 10. . What is the output for the program given below typedef enum errorType{warning, error, exception,}error; main() { error g1; g1=1; printf("%d",g1); } Ans- Compiler error: Multiple declaration for error 11. What is the output for the program given below typedef struct error{int warning, error, exception;}error; main() { error g1; g1.error =1; printf("%d",g1.error); } Ans-1 12. What is the output for the program given below? int aaa() {printf(“Hi”);} int bbb(){printf(“hello”);} int ccc(){printf(“bye”);} main() { int (* ptr[3]) (); ptr[0] = aaa; ptr[1] = bbb; ptr[2] = ccc; ptr[2](); } Ans-bye 13. What is the output for the program given below? main() { static int a[3][3]={1,2,3,4,5,6,7,8,9}; int i,j; static *p[]={a,a+1,a+2}; for(i=0;i<3;i++) { for(j=0;j++) printf(“%dt%dt%dt%dn”,*(*(p+i)+j); *(*(j+p)+i),*(*(i+p)+j),*(*(p+j)+i)); } } Ans- 1 1 1 1 2 4 2 4 3 7 3 7 4 2 4 2 5 5 5 5 6 8 6 8 7 3 7 3 8 6 8 6 9 9 9 9 14. Declare an array of N pointers to functions returning pointers to functions returning pointers to characters? Ans- (char*(*)( )) (*ptr[N])( ); 15. There were 10 records stored in “somefile.dat” but the following program printed 11 names. What went wrong? void main() { struct student { char name[3], rollno[6]; }stud; FILE *fp = fopen((“somefile.dat”,”r”); while(!feof(fp)) { fread(&styd,sizeof(stud), 1 , fp); puts(stud.name); } } 16. Is there any difference between the two declarations, 1. int foo(int *arr[]) and 2. int foo(int *arr[2]) Ans-No 17. What is the subtle error in the following code segment? void fun(int n, int arr[]) { int *p=0; int i=0; while(i++ p =&arr[i]; *p = 0; } 18. What is wrong with the following code? int *fool() { int *s = malloc(sizeof(int)100); assert(s!=NULL); return s; } 19. What is the hidden bug with the following statement? assert(val++ != 0); 20. Is the following code legal? struct a { int x; struct a b; } Ans-No 21. Is the following code legal? void main() { typedef struct a aType; aType someVariable; struct a { int x; aType *b; }; } Ans-no 22. Which version do you prefer of the following two, 1) printf(“%s”,str); // or the more curt one 2) printf(str); Ans-1 23. Find the output. main() { char a[4]="HELL"; printf("%s",a); } Ans- HELL%@!~@!@???@~~! 24. Printf can be implemented by using __________ list. Ans-Verbal Length argument 25. The command which gives the device of our system Ans-Who 26. Which of following is correct: a)For loops can be nested b)For Loops may use the same Index c)For loops cannot be overllapped Ans:a,c 27. when the system starts which will execute? Ans- Booting loader 28. ada is _____________ language a)modular b)object based c)object oriented d)functional 29. The maximum level of the tree is Ans-depth of the tree 30. which is used for storing pictures or graphics a) mbr b)mar c)frame buffer d)sdram