Sunday, July 04, 2004

 

Interview FAQ picked by mxclxp - 1

The following interview questions were picked by mxclxp http://blog.csdn.net/mxclxp from http://www.acetheinterview.com

1. C/C++

1、What is polymorphism?

'Polymorphism' is an object oriented term. Polymorphism may be defined as the ability of related objects to respond to the same message with different, but appropriate actions. In other words, polymorphism means taking more than one form.
Polymorphism leads to two important aspects in Object Oriented terminology - Function Overloading and Function Overriding.
Overloading is the practice of supplying more than one definition for a given function name in the same scope. The compiler is left to pick the appropriate version of the function or operator based on the arguments with which it is called.
Overriding refers to the modifications made in the sub class to the inherited methods from the base class to change their behaviour.



2、What is operator overloading?

When an operator is overloaded, it takes on an additional meaning relative to a certain class. But it can still retain all of its old meanings.

Examples:

1) The operators >> and << may be used for I/O operations because in the header, they are overloaded.

2) In a stack class it is possible to overload the + operattor so that it appends the contents of one stack to the contents of another. But the + operator still retains its original meaning relative to other types of data.

Also Polymorphism can be achieved in C++ through operator overloading

3、Declare a void pointer.

I think the answer is simply
void* p;

malloc is just the library function called to allocated some memory and of course a void pointer will be returned , but it is the declaration of a void pointer.

4、What are templates?

C++ Templates allow u to generate families of functions or classes that can operate on a variety of different data types, freeing you from the need to create a separate function or class for each type. Using templates, u have the convenience of writing a single generic function or class definition, which the compiler automatically translates into a specific version of the function or class, for each of the different data types that your program actually uses.

Many data structures and algorithms can be defined independently of the type of data they work with. You can increase the amount of shared code by separating data-dependent portions from data-independent portions, and templates were introduced to help you do that.

5、Type-define a function pointer which takes a int and float as parameter and returns a float *.

the pointer to function can be type defined as:
typedef float*(*pf)(int a, float b) tagPF;



6、What does the following C statement do?

while(*c++ = *d++); assuming c and d are pointers to characters.

String copy is performed indeed but be careful with the space allocated for the destination string.
Check this example:

char s1[10]="abcde";
char s2[3];

char* c,*d;
c=s2;
d=s1;
while(*c++ = *d++);
printf("%s - %s\n",s1,s2);

The code is string copy. But it does not add a null pointer to the end(*). There should also be a check for overlapping addresses(O).

7、How do you call a C module within a C++ module.

You should use extern "C" for functions, compiled by C compiler and called within a C++ class. You should do that to force the linker to resolve the function name (precisely, the mangling of the name) correctly.



8、What is the difference between run time binding and compile time binding? Discuss.

Compile Time Binding : In case of operator overloading and function overloading the name of the function is resolved during the compile time . Even if there are two or more functions with the same name the compiler mangles the name so that each function is uniquely identified . This has to be resolved at compile time and is known as compile-time binding or early binding.

Run Time Binding : In case of polymorphism (virtual functions) if a base class pointer(or reference) is allocated a pointer(or reference) of derived class the actual function called is determined only during runtime through the virtual table entry . This is runtime binding or late binding

9、Compare and contrast C++ and Java.

1>Platform Independent : Java code is said to be a multiplatform code and can run on any platform because after the compilation of the source code byte code(s) are created rather than a binary code so it can run on any platform which supports JVM concept but on the contrast at time(s) it slows down the application tremendously

2> Garbage Collection : Java handles freeing up of the memory but this is not guranteed since the GC thread has the lowest priority

3>Operator Overloading : is not provided in Java,but what are the advantages of Operator Overloading but one may question what are its advantages, well it makes a more readable and a modular code. In c++ cin and cout objects can also be overloaded which again leads to a better readability and flexibility

4> Multiple Inheritance : Java does provide multiple inheritance in form of Interfaces, In Java a class can not inherit from more than one class but it definitely can implement any number of interfaces

5> Templates: in c++ give such a lot of flexibility and avoids redundant coding which again is not provided by Java

10、Why does C/C++ give better run-time performance then Java?

That's because the Java bytecode is interpreted, not compiled. Programs
written in C are compiled into binaries which can be executed by a specific computer processor. Programs written in Java require one more step -- they must be interpreted by the Java "virtual machine" before running on a particular computer architecture. As a result, a computer running a Java program has to execute more machine-language instructions to do the same amount of work than a computer running an equivalent program written in C.



11、Does C++ come with in-built threading support.

No. C++ does not support in-built Multithreading. To do so, you must use the operating system functions manually. (Better use pthread library.)



12、Class A derived B derived C. All have foo(). I cast C to A and call foo(). What happens?(*)

--foo() for class C will be called.

--it depends. if in A foo is defined as virtual function. then call C's foo(), if it doesn't defined virtual, then call A's foo()

--Actually, if access is NOT specified, it deafults to private derivation. In private derivation, binding is static. So, whether foo is declared virtual or not it still defaults to static binding. So, A->foo() is called. However, If a public derivation is specified from C <-- B and B <-- A, then if foo() is virtual C->foo() is called; if foo() is non virtual A->foo() is called.

--But I think there is an important thing neglected by all of you, that is ‘cast C to A’, NOT ‘cast C* to A*’, So the correct answer is A.foo() will be called.

13、All classes A, B, C have default constructor, foo() that calls parent foo() and allocates 100 bytes to their own private local variable, and a destructor that frees the 100 bytes. I create a C object and then destroy it. What's the problem? Did all the memory get freed? What if I create C, cast to A, and then destroy it. How would I make sure memory is freed?

--destructor must be "virtual" and each destructor must call parent destructor



14、What errors are caught at compile time vs link time?

Syntactical and symantical errors (code errors) are caught at compile time.
Dependency errors (for example resolving function calls or errors in including other modules) are caught at link time.

15、What is the value of "a" after this?
int (*a) [10];
a++;

int (*a)[10]; represents the declaration of a pointer to an array of ten integers. So the value of a is initially some address allocated by the compiler and don't rely on the fact the address is 0 as it happens for static variables.
The value can be zero if you add the "static" keyword in front of declaration but I don't advise you to further use this pointer to access some elements.
If the integer is n bytes ( 2 or 4 depending on the language) it is true that the value of a will be increase with 10*n.

Test this program to understand:

#include

void main(int argc,char*argv[])
{
int b[10]={1,2,3,4};
int (*a)[10];
printf("%p\n", a); // invalid address!!
printf("%d\n",(*a)[0]); // runtime error!!
a++; // advance 10 * sizeof(int) bytes
printf("%p\n", a);
a=&b;
printf("%p\n", a);
printf("%d\n",(*a)[0]);
}

16、What is wrong with this?
main(){
int *ptr;
*ptr=10;
}

Actual reality is like this. When the pointer is declared it contains some garbage value as u know. Conceptually speaking it points to location indicated by that "garbage memory address". Now when we assign some value to *a ; i.e.
*a=12;
we are trying to place 12 in the memory cell number indicated by 'a' ; which in this case is any random memory address because it is garbage. So the program will be compiled fine. But when run ; if the garbage value assigned to 'a' is invalid (or restricted by OS) memory address ; the OS will generate error. So its upto OS.

But technically program is fine.
-Dhiraj

17、Given int n, i=10, j=20, x=3, y = 100;
What is the value of n and y at the end of each of the following expressions?
a) n = (i > j) && (x < ++y);
b) n = (j - i) && (x < y++);
c) n = (i < j)

1> n = 0, y = 100, second condition will not be evaluated.

2> n = 1, y = 101

3> n = 1, y = 100

18、int x = 5;
int y = 7;
What is the value of x and y after the expression y+=x++;
Y = 12 and X = 6
Why? because X will be incremented after y = Y+X has been carried out and result has been assigned to Y.
if it would have been y+=++x then the value of y would have been equal to 13 and x = 6
I am sure about this
Mohit

19、What's the difference between C and C++?

C is Top Down Approach
C++ is Bottom Up Programming approach.

C does not support OOP (Object Oriented Programming) and do not support PolyMorphism, Inheritence, Encapsulation, Function OverLoading.

There is an important difference but often neglected by many people is the error handling.

Some common C style commands and there corresponding C++ style commands are shown below.



Console I/O
***********
C
===
printf("Hello World!\n");
scanf("%s", name);
C++
===
cout << "Hello World!" << endl;
cin >> name;

Comments
********
C
===
/* comment */
C++
===
// comment

File extensions
***************
C
===
.c, .h
C++
===
.C, .h, .CPP, .HPP

File I/O
*********
C
===
out = fopen("output_file.dat", "wb");
in = fopen("input_file.dat", "rb");
C++
===
ofstream out("output_file.dat");
ifstream in("input_file.dat");

Dynamic Memory
**************
C
===
text = (char *) malloc(1000);
free(text);
C++
===
text = new char[1000];
delete [] text;

Constants
*********
C
===
#define PI 3.14159
C++
===
const float PI = 3.14159;

Macros
******
C
===
#define MAX(a,b) ((a) > (b) ? (a) : (b))
C++
===
inline int MAX(int a, int b) { return a > b ? a : b; }



20、What does Public and Private mean in C++

--Public:
Makes class memebrs accessible outside the class. It can be accessed in the C code.
Private:
Makes the members specified accessible only to the class and it's functions.
--public / private have two different meanings in C++:
1. To specify the access privilege of the class members.
2. To specify what type of inheritance.

21、Is it possible to keep 2 stacks in a single array, if one grows from position one of the array, and the other grows from the last position. Write a procedure PUSH(x,s) that pushes element x onto stack S, where S is one or the other of these two stacks. Include all necessary error checks (Sent by Puneet Saraf)

The question did not ask for a suggestion. It is definitely possible to implement 2 stacks using a single array. The array shud be visible to both stacks (and therefore be global, or shud provide equivalent effect). Also the stack tops shud be taken care of. one top will decrement everytime the push method is called and one would be incremented. As soon as s1.top==s2.top we shud throw an exception.

2. Databases

1. What are two methods of retrieving SQL?
Answer:



2. What cursor type do you use to retrieve multiple recordsets?
Answer:



3. What action do you have to perform before retrieving data from the next result set of a stored procedure?
Answer: Move the cursor down one row from its current position. A ResultSet cursor is initially positioned before the first row. Before you can get to the first row, you would need to Move the cursor down by one row ( For ex: in java the first call to next makes the first row the current row; the second call makes the second row the current row, and so on).



4. What is the basic form of a SQL statement to read data out of a table?
Answer: SELECT * FROM table_name;



5. What structure can you have the database make to speed up table reads?
Answer: The question is not correct. "What structure can you have the database make to speed up table reads?" It is not clear what exactly the term "structure" means in this case. Follow the rules of DB tuning we have to:
1) properly use indexes ( different types of indexes)
2) properly locate different DB objects across different tablespaces, files and so on.
3) Create a special space (tablespace) to locate some of the data with special datatypes( for example CLOB, LOB and ...)
4)...
5)...



6. What is a "join"?
Answer: Joins merge the data of two related tables into a single result set, presenting a denormalized view of the data.



7. What is a "constraint"?
Answer: A constraint allows you to apply simple referential integrity checks to a table. There are 5 primary types of constraints that are currently supported by SQL Server:
PRIMARY/UNIQUE - enforces uniqueness of a particular table column.
DEFAULT - specifies a default value for a column in case an insert operation does not provide one.
FOREIGN KEY - validates that every value in a column exists in a column of another table.
CHECK - checks that every value stored in a column is in some specified list
NOT NULL - is a constraint which does not allow values in the specific column to be null. And also it is the only constraint which is not a table level constraint.



8. What is a "primary key"?
Answer: Primary Key is a type of a constraint enforcing uniqueness and data integrity for each row of a table. All columns participating in a primary key constraint must possess the NOT NULL property.



9. What is a "functional dependency"? How does it relate to database table design?
Answer: What functional dependence in the context of a database means is that: Assume that a table exists in the database called TABLE with a composite primary key (A, B) and other non-key attributes (C, D, E). Functional dependency in general, would mean that any non-key attribute - C D or E being dependent on the primary key (A and B) in our table here.
Partial functional dependency, on the other hand, is another corollary of the above, which states that all non-key attributes - C D or E - if dependent on the subset of the primary key (A and B) and not on it as a whole.
Example :
----------
Fully Functional Dependent : C D E --> A B
Partial Functional dependency : C --> A, D E --> B
Hope that helps!



10. What is a "trigger"?
Answer: A trigger is a database object directly associated with a particular table. It fires whenever a specific statement/type of statement is issued against that table. The types of statements are insert, update, delete and query statements. Basically, trigger is a set of SQL statements that execute in response to a data modification/retrieval event on a table.
Other than table triggers there are also schema and database triggers. These can be made to fire when new objects are created, when a user logs in, when the database shutdown etc. Table level triggers can be classified into row and statement level triggers and those can be further broken down into before and after triggers. Before triggers can modify data.



11. What is "index covering" of a query?
Answer: A nonclustered index that includes (or covers) all columns used in a query is called a covering index. When SQL server can use a nonclustered index to resolve the query, it will prefer to scan the index rather than the table, which typically takes fewer data pages. If your query uses only columns included in the index, then SQL server may scan this index to produce the desired output.



12. What is a SQL view?
Answer: View is a precomplied SQL query which is used to select data from one or more tables. A view is like a table but it doesn't physically take any space. View is a good way to present data in a particular format if you use that query quite often.
View can also be used to restrict users from accessing the tables directly.
A view otherwise known as a virtual table is a mere window over the base tables in the database. This helps us gain a couple of advantages:
1) Inherent security exposing only the data that is needed to be shown to the end user
2) Views are updateable based on certain conditions. For example, updates can only be directed to one underlying table of the view. After modification if the rows or columns don't comply with the conditions that the view was created with, those rows disappear from the view. You could use the CHECK OPTION with the view definition, to make sure that any updates to make the rows invalid will not be permitted to run.
3) Views are not materialized (given a physical structure) in a database. Each time a view is queried the definition stored in the database is run against the base tables to retrieve the data. One exception to this is to create a clustered index on the view to make it persistent in the database. Once you create a clustered index on the view, you can create any number of non-clustered indexes on the view.

3. Internet Technologies

1、 What is HTTP? How does it work (in basic terms)?

HTTP: (HyperText Transport Protocol) The communications protocol used to connect to servers on the World Wide Web. Its primary function is to establish a connection with a Web server and transmit HTML pages to the client browser. Addresses of Web sites begin with an http:// prefix; however, Web browsers typically default to the HTTP protocol. Web browsers communicate with Web servers via the TCP/IP protocol. The browser sends HTTP requests to the server, which responds with HTML pages and possibly additional programs in the form of ActiveX controls or Java applets.

2、 What is a CGI program? How does one get invoked?

CGI(Common Gateway Interface script) A small program written in a language such as Perl, Tcl, C or C++ that functions as the glue between HTML pages and other programs on the Web server. For example, a CGI script would allow search data entered on a Web page to be sent to the DBMS (database management system) for lookup. It would also format the results of that search as an HTML page and send it back to the user. The CGI script resides in the server and obtains the data from the user via environment variables that the Web server makes available to it.
CGI scripts have been the initial mechanism used to make Web sites interact with databases and other applications. However, as the Web evolved, server-side processing methods have been developed that are more efficient and easier to program. For example, Microsoft promotes its Active Server Pages (ASPs) for its Windows Web servers, and Sun/Netscape nurtures its Java roots with JavaServer Pages (JSPs) and servlets

3、 What is the difference between GET and POST methods of submitting form data?

get-- This has a limit as to number of characters that it can pass. In get the request is sent in the the form of a query string from the web browser to the web server. The max. no. of characters that can be passed are 255. Since the request is sent in the query string that is visible in the address bar of the web browser, this method is not suited for passing confidential info. such as passwords/credit card no's etc.

post-- There is no such limit on the no. of characters that can be passed at a time as the request is passed in the body of the message. So this is useful for passing confidential data. Also, one can pass any length of info. to the server.

4、 What is "URL Encoding"?

URL Encoding is a method by which a string is converted into a format which is suitable for HTTP URL.
Example : Server.URLEncode("sitename=imilap")
Results is sitename%3Dimilap. = is converted into characters which can be used in the URL

5、 What is an HTML "entity"?

Character entity references, or entities for short, provide a method of entering characters that cannot be expressed in the document's character encoding or that cannot easily be entered on a keyboard. Entities are case-sensitive and take the form &name;. Examples of entities include © for the copyright symbol and Α for the Greek capital letter alpha.

6、 How can you do a "redirect" to another page?

This is easily achieved using the Meta tag as below
META HTTP-EQUIV="Refresh" CONTENT="3;URL=http://www.redirect.to.com">

But I think there are 2 aspects of the problem, redirect from the client side or the server side. As to the client side, if we are using VBScript, just call the navigate method of window object is OK, if not, we can set the window object’s location.href property to the URL of the target page. As to the server side, if differs from languages to languages.

7、 What web servers do you have experience with? Apache? IIS?

8、 How does an XML DTD work, and what are some of its limitations?

XML DTD: Extensible Markup Language Document Type Definition. It is to define the legal building blocks of an XML document. It defines the document structure with a list of legal elements. A DTD can be declared inline in your XML document, or as an external reference.

The drawbacks of DTD:
1) DTD doesn’t comply with the XML syntax,
2) The data types of DTD is limited,
3) DTD is not extensible,
4) DTD doesn’t support namespace.

9、 What are session variables?

When a user logs in a web site a session is created. Session variables are a variable which remain active throughout this session.

The use of Session variables is to store information pertinent to that particular session. Example: user preferences etc.

10、 What problems do the vendors of ODBC Technology face with ASP/ADO?

ADO's apartment threaded, and ASP doesn't support threading at all.
The main problem would be locking unnecessarily or dead-locking when multiple requests are made thru the same connection object.

11、 What are the three tags of a form tag in HTML form?

ACTION, METHOD, Target and EncType (encoding type)

12、 What are the two tags for framesets?

Frameset, frame and noframes. Example:

frameset framespacing="0" border="false" frameborder="0" rows="95,*">
frame name="banner" scrolling="no" noresize target="contents" src="indianlook_top.html">
frame name="main" src="http://www.imilap.com">
noframes>

This page uses frames, but your browser doesn't support them.
/noframes>
/frameset>

13、 How do you create Drop Down Combos in HTML?

Using Select tag. Example:

select name="gender">
option value="0" SELECTED>Male
option value="1" >Female
/select>

14、 In DHTML what is the difference between FontSize and Font Size?

FontSize is a property, Font Size is a style.

15、 What is the tag CodeBase and why do we use it?

After writing and compiling a Java applet, you can display it in a web page by using the APPLET tag. The CODE attribute specifies the name of the Java applet to run. The CODEBASE attribute specifies the subdirectory or folder containing the Java applet. You can use PARAM tags between the APPLET> and /APPLET> tags to provide information about parameters, or arguments, to be used by the Java applet.

Syntax
APPLET
CODE="classFileName"
CODEBASE="classFileDirectory"
ARCHIVE="archiveFile"
ALT="altText"
ALIGN="LEFT"|"RIGHT"|"TOP"|"ABSMIDDLE"|"ABSBOTTOM"| "TEXTTOP"| "MIDDLE" | "BASELINE" | "BOTTOM"
HEIGHT="height"
WIDTH="width"
HSPACE="horizMargin"
VSPACE="vertMargin"
NAME="value"
>
PARAM ...>
/APPLET>
The CODE attribute is required (otherwise there is no applet to run). Netscape Navigator 3 and Navigator 4 can display applets if the WIDTH and HEIGHT attributes are omitted, but some other browsers cannot, so for best results you should always include the WIDTH and HEIGHT attributes.

CODE ="classFileName"
specifies the filename of the applet to load. All Java class files end with a .class extension (for example, myApplet.class). Many browsers will display the applet correctly even if you omit the .class extension in the filename.

CODEBASE="classFileDirectory"
is the directory containing the applet class file and any resources the applet needs. The value is a URL for an absolute or a relative pathname. An absolute URL is used as is without modification and is not affected by the document's BASE tag. A relative CODEBASE attribute is relative to the document's base URL defined by the BASE tag. If the document does not define a BASE tag, it is relative to the directory containing the HTML file.

For short, the code property indicates the Qualified Class Name (including package name), ending with .class or not is both OK; the codebase is the well known classpath!

16、 Walk me through the OSI seven-layer model, then explain at what layer a switch, router and hub all operates.



7. Application layer
6. presentation layer
5. Session layer
4. Transport layer
3. Network layer
2. Datalink layer
1. Physical layer



A hub is a physical layer device providing absolute NO intelligence. A switch is a data link layer device which isolates collision domains vs. routers which isolate broadcast domains, giving each connection to a switch a "private" connecting (no collisions/contention). Think of a switch as a multi-port bridge of sorts, allocation a time slice to each connection, but very quickly.

17、 Describe how DNS works. Describe the difference between a resolver and an authoritative master server.



18、 Describe TCP/IP and it's components. What is ARP/RARP? What does a TCP/IP packet looks like?

Address Resolution Protocol (ARP) performs IP address-to-Media Access Control (MAC) address resolution for outgoing packets.



19、 Describe the process that happens when you click a link in your web browser to fetch another web page.



20、 How would you design the web page for a company that sells screws?How can you have different number of cells for each row of a table?

Its just sufficient to give the number of column tags within the row tags ... and its fine if the cells are varying within each rows.
Colspan will help you keep the alignment of your overall table, that is avoids the step or zig-zag pattern due to different no. of cells in different rows.




<< Home

This page is powered by Blogger. Isn't yours?