Amazon Latest Placement Paper Pattern

Discussion in 'Latest Placement papers' started by krishan, Sep 1, 2014.

  1. Written Test has 2 Sections A, B



    In Section A there were 20 Questions:



    Technical Questions :15



    Aptitude:5



    Time Limit :30 min



    Small Answer Type



    Multiple choice



    Aptitude-5



    The first round was online. It had 20 mcq’s and 2 code’s.MCQ’s where quite simple, it had 15 tech. and 5 apti. Technical where easy it had q’s on finding the o/p,complexity,and more importance was in DS, and especially TREE.



    The two coding q’s where as below.

    1) Finding all possible UNIQUE substings of and array of char. And displaying it in sorted order.



    2) It was on tree was easy. I don’t remember the exact question.



    Some Sample Questions



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



    2.Display the employees whose salary is less than average salary.



    3.what is the output of the program
    main()
    {
    int c=5;
    printf("%d %d %d",c,c<<2,c>> 2);
    }



    4.
    main()
    {
    int a[8][10],c=0,i,j;
    for(i=0;i<10;
    i++) for(j=0;
    j<8;j++) a[j]=c++;
    printf("%d",a[3][6]);
    }



    5.What is the wrong in this program
    main()
    {
    char *p,*q;
    p=(char *)malloc(25);
    q=(char*) malloc(25);
    strcpy(p,"amazon" );
    strcpy(q,"hyd");
    strcat(p,q);
    printf("%s",p);
    }



    6.write prefix and post fix notation for (a+b)*c-(d+e)^(f-g)



    7.what is the output of the program
    main()
    {
    int i=5;
    printf("%d",fun(fun(fun(fun( fun(i))))));
    }
    void fun(int i)
    { if(i%2) return (i+(7*4)-(5/2)+(2*2));
    else return (i+(17/5)-(34/15)+(5/2));
    }

    8.When it is always true boolean fun

    (node *p)
    {
    return ((p==null)||(p->next==null)|| (p->info<=p->next->info)&&( fun(p->next)));
    }

    a)when list is empty or has one node
    b)when the ele are sorted in non decreasing order
    c)when the ele are sorted in non increasing order



    9.what is x here (x&&!(x&(x-1))==1)
    a)x is always a prime
    b)x is a power of 2
    c)x is even d)x is odd



    10 .What is the difference between deep copy and shallow copy



    11.In java what is the difference between sleep() and wait() .



    12.What happens when the parent process of a child process exits before the child ?



    13.There are three persons A,B,C .A shots the target 6 times out of 7 shots .B shots 4 out of 5 shots .Then what is the probability of hitting the target twice when 2 persons are selected at random.



    14.what is valid in cpp char *cp; const char *cpp; 1) cpp=cp; 2) cp=cpp;



    15.write program to swap 2 variables without using extra memory.



    16.write a shell command to find all java files present in nested directories.



    17.There are 6 pairs of black socks and 6 pairs of white socks. What is the probability to pick a pair of black or white socks when 2 socks are selected randomly in darkness.



    18.A string of alphanumeric is there. Find a string that starts with b and ends with 3 characters. section B (we have to write programs) time:30 min



    1.There is a sorted array which is of very large size.In that all except one no. are repeated once.How to find that non repeated no.


    2.There are 2 linked lists.Those 2 lists are meeting at a point. How to find that meeting point.



    Latest Amazon Interview Questions -1


    1. How do you convert a decimal number to its hexa-decimal equivalent.Give a C code to do the same

    2. Explain polymorphism citing an example.

    3. What are the 4 basics of OOP?

    4. Define Data Abstraction. What is its importance?

    5. Given an array all of whose elements are positive numbers, find the maximum sum of a subsequence with the constraint that no 2 numbers in the sequence should be adjacent in the array.
    Eg.
    i) 3 2 7 10 should return 13 (sum of 3 and 10)
    ii) 3 2 5 10 7 should return 15 (sum of 3, 5 and 7)


    6. Given a Binary Search Tree, write a program to print the kth smallest element without using any static/global variable. You can’t pass the value k to any function also.


    7.You are given some denominations of coins in an array (int denom[])and infinite supply of all of them. Given an amount (int amount), find the minimum number of coins required to get the exact amount. What is the method called?


    8.Given an array of size n. It contains numbers in the range 1 to n. Each number is present at least once except for 1 number. Find the missing number.


    9.Given an array of size n. It contains numbers in the range 1 to n. Each number is present at least once except for 2 numbers. Find the missing numbers.


    10.Given an array of size n. It contains numbers in the range 1 to n. Find the numbers which aren't present.


    1.Given a string,find the first un-repeated character in it? Give some test cases


    2.You are given a dictionary of all valid words. You have the following 3 operations permitted on a word:
    a) Delete a character
    b) Insert a character
    c) Replace a character
    Now given two words - word1 and word2 - find the minimum number of steps required to convert word1 to word2. (one operation counts as 1 step.)


    3.Given a cube of size n*n*n (i.e made up of n^3 smaller cubes), find the number of smaller cubes on the surface. Extend this to k-dimension.

    4.What is a C array and illustrate the how is it different from a list.

    5. What is the time and space complexities of merge sort and when is it preferred over quick sort?

    6. Write a function which takes as parameters one regular expression(only ? and * are the special characters) and a string and returns whether the string matched the regular expression.

    7. Given n red balls and m blue balls and some containers, how would you distribute those balls among the containers such that the probability of picking a red ball is maximized, assuming that the user randomly chooses a container and then randomly picks a ball from that.

    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. Given an array of size n ,containing every element from 1 to n+1, except one. Find the missing element.



    10 There are two urns A and B and an equal number of red balls and blue balls.How do u place the balls in the urns such that the probability of picking up the red ball is greater?


    11 Two trains enter at the opposite sides of a tunnel of length L with speeds 'V'. A particle enters the tunnel at the same time with a speed 'v' and it vibrates in the tunnel[i.e. if it reaches the end of the tunnel then it comes back]. What is the position of the particle by the time the 2 trains meet?


    12 Write an sql query to sort a table according to the amounts in a row and find the second largest amount.

    13 How do you kill a process?

    14 What is the functionality of a top command?

    15 Given an array of size n+1 which contains all the numbers from 1 to n.Find the number which is repeated in O(n) time .How do you proceed with the same with floating numbers

    from 0 to 1 instead of 1 to n?

    16 Design a data structure to represent the movement of a knight on a chess board

    17 Write an algorithm to traverse a knight covering all the squares on a chessboard starting at a particular point.

    18)Place a red ball in a urn and all the further balls in the other urn.The probability for picking out the red ball is now greater than 0.5.
    19)If v<=2V then the position is (v*L)/(2*V) from the starting point else it is 2*L -(v*L)/(2*V) from the starting point.

    20If we know the process then we can kill it by killall -9 "process name" else we can kill it using its process id obtained by the command ps -x by kill -9 "processid" .

    21Top command displays all the Linux tasks running at that particular time.It provides their running time and the resources used.

    22The number appearing 2 times is (sum of all the numbers in the array) - (sum of the numbers from 1 to n).
    For floating numbers multiply it with 100 and proceed.
  2. Amazon OOPS Interview Questions

    1. What are the major differences between C and C++?



    2. What are the differences between new and malloc?



    3. What is the difference between delete and delete[?



    4. What are the differences between a struct in C and in C++?



    5. What are the advantages/disadvantages of using #define?



    6. What are the advantages/disadvantages of using inline and const?



    7. What is the difference between a pointer and a reference?



    8. When would you use a pointer? A reference?



    9. What does it mean to take the address of a reference?



    10. What does it mean to declare a function or variable as static?



    11. What is the order of initialization for data?



    12. What is name mangling/name decoration?



    13. What kind of problems does name mangling cause?



    14. How do you work around them?



    15. What is a class?



    16. What are the differences between a struct and a class in C++?





    17. What is the difference between public, private, protected, and friend access?



    18. For class CFoo { }; what default methods will the compiler generate for you>?



    19. How can you force the compiler to not generate them?



    20. What is the purpose of a constructor? Destructor?



    21. What is a constructor initializer list?



    22. When must you use a constructor initializer list?

    What is a:
    * Constructor?
    * Destructor?
    * Default constructor?
    * Copy constructor?
    * Conversion constructor?

    What does it mean to declare a...
    * member function as virtual?
    * member function as static?
    * member variable as static?
    * destructor as static?



    1.Can you explain the term "resource acquisition is initialization?"



    2.What is a "pure virtual" member function?



    3.What is the difference between public, private, and protected inheritance?



    4.What is virtual inheritance?



    5.What is placement new?



    6.What is the difference between operator new and the new operator?



    7.What is exception handling?


    8.Explain what happens when an exception is thrown in C++.


    9.What happens if an exception is not caught?


    10.What happens if an exception is throws from an object's constructor?


    11.What happens if an exception is throws from an object's destructor?



    12.What are the costs and benefits of using exceptions?


    13.When would you choose to return an error code rather than throw an exception?


    14.What is a template?


    15.What is partial specialization or template specialization?


    16.How can you force instantiation of a template?


    17.What is an iterator?


    18.What is an algorithm (in terms of the STL/C++ standard library)?


    19.What is std::auto_ptr?


    20What is wrong with this statement?
  3. std::auto_ptr ptr(new char[10]);
    It is possible to build a C++ compiler on top of a C compiler. How would you do this?
    More advanced questions:

    * What is a vtbl ?

    * What is RTTI and why do you need it?


    * How do I specialize a template? Give an example.


    To separate sheep from goats (for those claiming C++ Guru status):


    * What is a partial template? Why would you use one?


    * How to I create a binary functor in the STL?


    Given the following code:
    class A;
    class B;
    class C {
    A* a_;
    B* b_;
    public:
    };


    *Implement a copy constructor and assignment operator for C. A sample solution is something like:
    class C {
    A* a_;
    B* b_;
    void swap(C& rhs) { rhs.a_ = a_; rhs.b_ = b_; }
    public:
    C(const C& rhs) {
    auto_ptr<> a(new A(rhs.a_));
    auto_ptr<> b(new B(rhs.b_)):
    delete a_;
    delete b_;
    a_ = a.release();
    b_ = b.release();
    }
    C& operator=(const C& rhs) {
    C temp(rhs);
    temp.swap(*this);
    return *this;
    }
    };


    What is wrong with this class, assuming that this is its complete interface?

    class C {
    char *p;
    public:
    C() { p = new char[64]; strcpy(p, "Hello world"); }
    ~C() { delete p; }
    void foo() { cout << "My ptr is: '" << p << "'" << endl; }
    };


    Since this has an overtly programmed destructor, the member wise semantics for destruction are not good enough; therefore, they are not good enough for copy and assignment either. But, the copy ctor and op= are not programmed, so we will have some serious trouble.
    Gradual hinting: what happens when we make a copy? [correct answer: pointer is copied]. Now, the original goes out of scope, what happens to the copy? [pointer dangles]. How would you fix it?
    [also, that delete p should be delete[ p since p was allocated with the array new]
    Assuming that swap() and copy construction are part of your interface for class C, what's the cookie-cutter pattern for operator= that uses them?
    answer:

    C& C:perator=(const C &rhs) {
    if (this != &rhs) {
    C tmp(rhs);
    this->swap(tmp);
    }
    return *this;
    }
    ]]





    There were two subjective questions

    1. The first one was “given two lists write a function which returns a list which is the intersection of the two lists.the original lists should remain same.
    (Intersection – if first list is say,1,20 3,45 and second list is 3,24 ,45,90,68 then intersection should be 3,45 )

    2. The second was given two nodes of a binary tree find the closest ancestor of the two nodes.
    Note:consider binary tree and binary search tree also.

    In short answer type questions, the questions were

    1.There was an aptitude’s question in which P(A) and P(B) were given and we had to find P(B/A) and P(A/B) when A and B are independent events.

    2.What is the probability that the the 4 digit’s no. which is formed by using the digits 1,2,3,4,5,6 is divisible by 4.

    3.What tree traversal gives the no. in sorted order.Inorder,preorder or postorder ?

    4.Preorder and inorder traversal was given and we had to find the tree.


    Amazon Interview questions

    1. Write an algorithm to determine if 2 linked lists intersect

    2. Find the 2nd-largest node in a binary tree

    3. Probably the most difficult question they asked me was, he put a binary tree on the whiteboard and I had to write a function that would find if the tree was symmetrical or not. Anyone who's familiar with data structures and recursion should be fine with this, just don't freak out when they propose the question.

    4. Find the element from the array that has odd number of occurences

    5. Generate words from a n *n matrix

    6. How would you, specifically, build Amazon Web Services?

    In an Amazon Fulfillment center, it takes a quality specialist 20 minutes to perform a damage-free check of one laptop. A temporary contractor takes 60 minutes to perform the same task.


    1How many hours does it take a quality specialist and a temporary contractor together to perform a damage-free check of a batch of 160 laptops?

    135 hours 40 hours 60 hours 24 hours

    2An space rocket travels around the Earth at a speed of approximately 18.5 miles per second. This approximate speed is how many miles per hour?

    1,080 1,16064, 80066, 600

    3If x-4 is 6 more than y, then x+9 is how much more than y+5?

    10 12 14 17

    4The first generation of the Galaxy 1 smartphone used to have a battery life of 20 hours. The new Galaxy 2 has smaller batteries with 40% less capacity. Also, the operating system of the Galaxy 2 consumes on average 50% less battery than the one of Galaxy 1. What is the battery life of Galaxy 2?

    24 hours 26 hours 30 hours 36 hours

    5Exactly 1/5 of the clients who entered Mike's shop yesterday were women. If exactly one third of the women were blonde, what is the minimum possible number of clients that entered the shop yesterday?



    6Amazon.it had 140 thousand visits on Friday, including new and returning visitors. Statistics show that for 5 new visitors there were 3 returning visitors (ratio of 5:3). What was the difference between new visitors and returning visitors on Friday?

    15 thousand 25 thousand 35 thousand 75 thousand

    7Amazon is negotiating with a carrier (SEUR) that will ship products from Amazon's wharehouse in Madrid to clients within the same city. SEUR charges Amazon per shipment based on the DISTANCE between Amazon's wharehouse to the client's address - €2 fixed for the first 2 kilometers and €0.5 per additional kilometer (measured by the meter, not by whole kilometers) for each delivery within a given city. 20% of clients live within 2 kilometers of Amazon’s wharehouse in Madrid - on average they live 1 km away. If all Amazon’s clients in Madrid live on average 4.5 kilometers away from Amazon's wharehouse, what is the estimated average shipping cost per delivery in Madrid, with SEUR?

    8A supplier of Amazon increases the price of a Book “Cooking for Children”) by 30% from last year and Amazon has planned to acquire additional stock with total (cost) value of 10,5% higher than last year’s stock acquisition. , By what % should Amazon reduce the quantity of “Cooking for Children” books that will buys,with regards to last year?

    19.5% 12% 8%

    There are ONLY 3 brands of video consoles (A, B and C). In 2010 A and B together represented 50% of units sold. C sold 3 million more units than A. Also, C sold 2.5 times the same units sold by B. If all video consoles had the same price of €300, what was the total video console market value in 2010?

    Three years ago, a son was 25 years younger than his father. At present the father is 6 times as old as the son. How old will the son be three years from now?

    5 9 8 11

    5 10 15 20
  4. 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<studio.h>

    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);

    return 0;

    }

    void fun(int n, int arr[])

    {

    int *p=0;

    int i=0;

    while(i++ < n)

    p = &arr;

    *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<stdio.h>

    int main()

    {

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

    printf(“%u, %u, %u\n”, 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!=’\0’)

    { length++; s++; }

    }




    B –

    int xsrrlen(char s)

    {

    int length=0;

    while(*s!=’\0’)

    length++; s++;

    return (length);

    }





    C-

    int xstrlen(char *s)

    {

    int length=0;

    while(*s!=’\0’)

    length++

    return (length);

    }

    Ans-A



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

    #include<stdio.h>

    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 '\0'.

    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<stdio.h>

    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.name, &e.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<stdio.h>

    int main()

    {

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

    printf("%d, %d, %d, %d, %d, %d\n", 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<stdio.h>

    struct course

    {

    int courseno;

    char coursename[25];

    };

    int main()

    {

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

    { 103, “PHP”},

    {104, “DotNet”} };

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

    printf(“%s\m”, (*(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<stdio.h>

    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<stdio.h>

    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<stdio.h>

    Int main()

    {

    printf(“%f\n”, lof(36.0));

    return 0;

    }

    A. #include<conio.h>

    B. #include<math.h>

    C. #include<stdlib.h>

    D. #include<dos.h>

    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<stdio.h>

    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
  5. 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<studio.h>

    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);

    return 0;

    }

    void fun(int n, int arr[])

    {

    int *p=0;

    int i=0;

    while(i++ < n)

    p = &arr;

    *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<stdio.h>

    int main()

    {

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

    printf(“%u, %u, %u\n”, 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!=’\0’)

    { length++; s++; }

    }




    B –

    int xsrrlen(char s)

    {

    int length=0;

    while(*s!=’\0’)

    length++; s++;

    return (length);

    }





    C-

    int xstrlen(char *s)

    {

    int length=0;

    while(*s!=’\0’)

    length++

    return (length);

    }

    Ans-A



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

    #include<stdio.h>

    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 '\0'.

    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<stdio.h>

    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.name, &e.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<stdio.h>

    int main()

    {

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

    printf("%d, %d, %d, %d, %d, %d\n", 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<stdio.h>

    struct course

    {

    int courseno;

    char coursename[25];

    };

    int main()

    {

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

    { 103, “PHP”},

    {104, “DotNet”} };

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

    printf(“%s\m”, (*(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<stdio.h>

    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<stdio.h>

    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<stdio.h>

    Int main()

    {

    printf(“%f\n”, lof(36.0));

    return 0;

    }

    A. #include<conio.h>

    B. #include<math.h>

    C. #include<stdlib.h>

    D. #include<dos.h>

    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<stdio.h>

    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
  6. 29. What will be the output of the program?

    #include<stdio.h>

    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++)

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

    }


    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 %d\n”,a,*a,**a,***a);

    printf(“%u %u %u %d\n”,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(“%d\t%d\t%d\t%d\n”,*(*(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;

    *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

Share This Page