Monday 23 May 2011

Technical interview "C" questions FAQ


What is the data structures used to perform recursion?
Stack. Because of its LIFO (Last In First Out) property it remembers its caller, so knows whom to return when the function has to return. Recursion makes use of system stack for storing the return addresses of the function calls. Every recursive function has its equivalent iterative (non-recursive) function. Even when such equivalent iterative procedures are written, explicit stack is to be used.

What is a memory leak?
Its an scenario where the program has lost a reference to an area in the memory. Its a programming term describing the loss of memory. This happens when the program allocates some memory but fails to return it to the system
printf() Function- What is the difference between "printf(...)" and "sprintf(...)"?
sprintf(...) writes data to the character array whereas printf(...) writes data to the standard output device.

What is data structure?
A data structure is a way of organizing data that considers not only the items stored, but also their relationship to each other. Advance knowledge about the relationship between data items allows designing of efficient algorithms for the manipulation of data.
http://materialsforjob.blogspot.com
What are the methods available in storing sequential files ?
Straight merging, Natural merging, Polyphase sort, Distribution of Initial runs.

What is a spanning Tree?
A spanning tree is a tree associated with a network. All the nodes of the graph appear on the tree once. A minimum spanning tree is a spanning tree organized so that the total edge weight between nodes is minimized
http://materialsforjob.blogspot.com
If you are using C language to implement the heterogeneous linked list, what pointer type will you use?
The heterogeneous linked list contains different data types in its nodes and we need a link, pointer to connect them. It is not possible to use ordinary pointers for this. So we go for void pointer. Void pointer is capable of storing pointer to any type as it is a generic pointer type.
http://materialsforjob.blogspot.com
How do you reverse a linked list without using any C pointers?
One way is to reverse the data in the nodes without changing the pointers themselves. One can also create a new linked list which is the reverse of the original linked list. A simple C program can do that for you. Please note that you would still use the "next" pointer fields to traverse through the linked list (So in effect, you are using the pointers, but you are not changing them when reversing the linked list).
http://materialsforjob.blogspot.com
printf() Function
What is the output of printf("%d")?
http://materialsforjob.blogspot.com
1. When we write printf("%d",x); this means compiler will print the value of x. But as here, there is nothing after %d so compiler will show in output window garbage value.

2. When we use %d the compiler internally uses it to access the argument in the stack (argument stack). Ideally compiler determines the offset of the data variable depending on the format specification string. Now when we write printf("%d",a) then compiler first accesses the top most element in the argument stack of the printf which is %d and depending on the format string it calculated to offset to the actual data variable in the memory which is to be printed. Now when only %d will be present in the printf then compiler will calculate the correct offset (which will be the offset to access the integer variable) but as the actual data object is to be printed is not present at that memory location so it will print what ever will be the contents of that memory location.

3. Some compilers check the format string and will generate an error without the proper number and type of arguments for things like printf(...) and scanf(...).
http://materialsforjob.blogspot.com
List out the areas in which data structures are applied extensively?
Compiler Design, Operating System, Database Management System, Statistical analysis package, Numerical Analysis, Graphics, Artificial Intelligence, Simulation

List out few of the Application of tree data-structure?
The manipulation of Arithmetic expression, Symbol Table construction, Syntax analysis.

Compilation How to reduce a final size of executable?
Size of the final executable can be reduced using dynamic linking for libraries
http://materialsforjob.blogspot.comhttp://materialsforjob.blogspot.com
Given only a pointer to a node to be deleted in a singly linked list, how do you delete it?
The solution to this is to copy the data from the next node into this node and delete the next node!. Ofcourse this wont work if the node to be deleted is the last node. Mark it as dummy in that case. If you have a Circular linked list, then this might be all the more interesting. Try writing your own C program to solve this problem. Having a doubly linked list is always better.

http://materialsforjob.blogspot.com
What is a NULL pointer? How is it different from an unitialized pointer? How is a NULL pointer defined?
Null pointer simply means "I am not allocated yet!" and "I am not pointing to anything yet!".
The C language definition states that for every available pointer type, there is a special value which is called the null pointer. It is guaranteed to compare unequal to a pointer to any object or function.
A null pointer is very different from an uninitialized pointer. A null pointer does not point to any object or function; but an uninitialized pointer can point anywhere.
There is usually a null pointer for each type of a pointer, and the internal values of these null pointers for different pointer types may be different, its up to the compiler. The & operator will never yield a null pointer, nor will a successful call to malloc() (malloc() does return a null pointer when it fails).
execl("/bin/ls", "ls", "-l", (char *)0);
In this call to execl(), the last argument has been explicitly casted to force the 0 to be treated as a pointer.
Also, if ptr is a pointer then
if(ptr){}
and
if(!ptr){}
are perfectly valid.
How is NULL defined?,
ANSI C allows the following definition
#define NULL ((void *)0)
NULL and 0 are interchangeable in pointer contexts.
Make sure you are able to distinguish between the following : the null pointer, the internal representation of a null pointer, the null pointer constant (i.e, 0), the NULL macro, the ASCII null character (NUL), the null string ("").

Tuesday 17 May 2011

Amazon interview questions

  1. 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.
  2. What are the 4 basics of OOP?
  3. Define Data Abstraction. What is its importance?
  4. 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.
  5. Given an array of size n. It contains numbers in the range 1 to n. Find the numbers which aren’t present.
  6. Given a string,find the first un-repeated character in it? Give some test cases
  7. You are given a dictionary of all valid words. You have the following 3 operations permitted on a word: delete a character, insert a character, 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.)
  8. 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.
  9. What is a C array and illustrate the how is it different from a list.
  10. What is the time and space complexities of merge sort and when is it preferred over quick sort?
  11. 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.
  12. 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.
  13. 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.
  14. Given an array of size n, containing every element from 1 to n+1, except one. Find the missing element.
  15. How do you convert a decimal number to its hexa-decimal equivalent.Give a C code to do the same
  16. Explain polymorphism. Provide an example.
  17. 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. So 3 2 7 10 should return 13 (sum of 3 and 10) or 3 2 5 10 7 should return 15 (sum of 3, 5 and 7)
  18. 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?
  19. 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.

Monday 16 May 2011

Technical Interview C++ Interview Questions


1. What is a class?

Ans:

class is a user defined data type,in which data members and member functions are defined.A class can also be defined as a classification/category of objects that have similar
attributes and behaviour.For example, Automobile is a category of objects that have similar attributes, such as wheels, engine, doors, shape, color, cylinders etc., and behaviours,
such as start, run, move, turn etc. Car is an instance of automobile which has different values for the attributes (4 wheels, one engine, 2 or 4 doors, 4/6/8 cylinders, etc),
http://materialsforjob.blogspot.com/


2.What is public, protected, private?
Ans:
public, protected, private are access specifiers that is used to implement encapsulation of data at various level.

Private:

* Can be data or method members
* Are private to the class where they are declared
* Accessible ONLY by the member methods of the class where they are declared
* Only exception to the above rule is Friend (explanation of friends is beyond the scope of this topic
* In a C++ class, private is default for member declaration. That is, if you do not specify any access specifier (private, public, protected), the member is considered private

Public:

* Can be data or method members
* Are accessible by any function/method/application globally, so long as an instance of the class where the public members are declared is created.
* These members are accessible only thru an instance of the class where they are declared
* Generally used to define a C++ class behaviour and/or to access private data members (act as private data modifiers)

Protected

* Can be data or method members
* Act exactly as private members for all practical purposes, so long as they are referenced from within the class (and/or instances of the class)where they are declared
* Specifically used to define how certain data/method members of a class would behave in a child class (used to define their behaviour in inheritance)
* The protected members become private of a child class in case of private inheritance, public in case of public inheritance, and stay protected in case of protected inheritance.http://materialsforjob.blogspot.com/


3.What is an object?

Ans:

In C++, Object is an instance of a Class that has a runtime state, and is associated with certain specific methods that can change its state.







4.Difference between realloc() and free()?

Ans:
http://materialsforjob.blogspot.com/
Realloc() is used to reallocate the memory for variable.Realloc()used to resize the memory held by the pointer to the number of bytes specificed.If the new
size is larger than current size, new memory is allocated. If it is less, the remaining (additional) bytes are released to general OS/application consumption.

Free() is used to free the allocated memory of a variable.

5. What is function overloading and operator overloading?

Ans:
http://materialsforjob.blogspot.com/
Function overloading: C++ enables several functions of the same name to be defined, as long as these functions have different sets of parameters (at least as far as their types
are concerned). This capability is called function overloading. When an overloaded function is called, the C++ compiler selects the proper function by examining the number,
types and order of the arguments in the call. Function overloading is commonly used to create several functions of the same name that perform similar tasks but on different data types
For example, void Function_Test();
void Function_Test(int); // Overloaded
void Function_Test(int, int); // Overloaded

Operator overloading allows existing C++ operators to be redefined so that they work on objects of user-defined classes. Overloaded operators are syntactic sugar for equivalent function calls.
They form a pleasant facade that doesn't add anything fundamental to the language (but they can improve understandability and reduce maintenance costs).

6. What is virtual class and friend class?

Ans:
http://materialsforjob.blogspot.com/
Virtual Base Class: Used in context of multiple inheritance in C++. If you plan to derive two classes from a class, and further derive one class from the two classes in the second level, you
need to declare the uppermost base class as 'virtual' in the inherited classes. This prevents multiple copies of the uppermost base class data members when an object of the class at the
third level of hierarchy is created.

Friend class: When a class declares another class as its friend, it is giving complete access to all its data and methods including private and protected data and methods to the friend
class member methods.
Friendship is not bi-directional. If A declares B as its friend it does NOT mean that A can access private data of B. It only means that B can access all data of A.

7. What is abstraction?

Ans:http://materialsforjob.blogspot.com/
Abstraction refers to the act of representing essential features without including the background details.That means abstraction is separating the logical properties from implementation details.
For example driving the car is a logical property and design of the engine is the implementation detail.

8. What do you mean by inline function?

Ans:http://materialsforjob.blogspot.com/
The idea behind inline functions is to insert the code of a called function at the point where the function is called. If done carefully, this can improve the application's performance in exchange
for increased compile time and possibly (but not always) an increase in the size of the generated binary executables.When an inline Function is invoked the code of function is inserted instead of
jump to code of function.

9. What do you mean by pure virtual functions?

Ans:
http://materialsforjob.blogspot.com/
A pure virtual member function is a member function that the base class forces derived classes to provide. Normally these member functions have no implementation. Pure virtual functions are equated to zero.

class Shape {

public:

virtual void draw() = 0;
};

10. What is virtual constructors/destructors?

Ans:
http://materialsforjob.blogspot.com/
Virtual constructor: Constructors cannot be virtual. Declaring a constructor as a virtual function is a syntax error.

Virtual destructors: If an object (with a non-virtual destructor) is destroyed explicitly by applying the delete operator to a base-class pointer to the object,
the base-class destructor function (matching the pointer type) is called on the object.

11. What is a scope resolution operator?

Ans:
A scope resolution operator (::) can be used to define the member functions of a class outside the class.Most generally a scope resolution operator is required when a data member is redefined by a derived class,
or an overriden method of the derived class wants to call the base class version of the same method.

12. what is difference between constructor and destructor?

Ans:
Constructor is the memeber function of the class which has the same name as that of class and it is invoked whenever the class object is instantiated.Using construtor we can allocate memory.

Destructor is also the member function of same class name and has ~ operator when ever declared in the function and it is used to destruct the object which has been constructed ,whenever we want to destroy it..

Tuesday 10 May 2011

PHP Interview Questions and answers 2


sessions and cookies

Face to face technical interviews, questions related to sessions and cookies will pop up regularly. Since most of the developers are familiar with these sort of basic php questions they tend to ask more tricky questions, but if you have the correct idea then it is easy to answer any of those tricky questions. Let’s have a look on potential questions,
Where is the sessions are stored?
Sessions are stored in server side and it is accessed by a unique id which is known as the session-id where each user/visitor is assigned when they access your website.
How the session-id is propagated within your website?
Basically, there are 2 methods either store it in a cookie or propagated in the URL.
Session security questions will not be asked in an entry level interviews but, if an advanced level candidate who has experience in developing robust and secured application must know about the vulnerabilities.
Leaking out an existing session-id to a third party is very risky if the session is filled with more important information.
Main two methods of vulnerabilities are,
- When the session-id is carrying in URLs
If an external link from your site, a URL with the id might be stored in the external site’s referrer log.
- Active attacker might listen to network traffic
While the session-id flows over the network and if it is not encrypted an active listener might grab it. The best solution is to implement SSL and make it a must for all the users.

Blue print of an object

What is the construct used to define the blueprint of an object called?
A class is a blueprint of an object, which is an instance of a class.

 

 

Saturday 7 May 2011

C++ developer interview questions

  1. Will the following program execute?void main()
    {
    void *vptr = (void *) malloc(sizeof(void));
    vptr++;
    }
  2. How about this one?
    void main()
    {
    char *cptr = 0?2000;
    long *lptr = 0?2000;
    cptr++;
    lptr++;
    printf(” %x %x”, cptr, lptr);
    }
    Will it execute or not?
  3. When the processor wakes up after power on, it goes to a particular memory location. What is that memory location called?
  4. What is the difference between Mutex and Binary semaphore?
  5. Write a program to set 2nd bit in a 32 bit register with memory location 0×2000?

Sunday 1 May 2011

Hardware architecture interview questions

  1. Are you familiar with the term MESI?
  2. Are you familiar with the term snooping?
  3. Describe a finite state machine that will detect three consecutive coin tosses (of one coin) that results in heads.
  4. In what cases do you need to double clock a signal before presenting it to a synchronous state machine?
  5. You have a driver that drives a long signal & connects to an input device. At the input device there is either overshoot, undershoot or signal threshold violations, what can be done to correct this problem?
  6. For a single computer processor computer system, what is the purpose of a processor cache and describe its operation?
  7. Explain the operation considering a two processor computer system with a cache for each processor.
  8. What are the main issues associated with multiprocessor caches and how might you solve it?
  9. Explain the difference between write through and write back cache.
  10. What are the total number of lines written in C/C++? What is the most complicated/valuable program written in C/C++?
  11. What compiler was used?
  12. Have you studied busses? What types?
  13. Have you studied pipelining? List the 5 stages of a 5 stage pipeline. Assuming 1 clock per stage, what is the latency of an instruction in a 5 stage machine? What is the throughput of this machine ?
  14. How many bit combinations are there in a byte?
  15. What is the difference between = and == in C?
  16. Are you familiar with VHDL and/or Verilog?

Search here for "Freshers Jobs"