hp placement paper

44
HP Placement Papers and Sample Papers The test comprises of 4 sections: Section A. ------50qns(general appitude,english etc): Section B. ------ 10 Questions on Computer concepts . Section C. ------ 30 Questions on C 1. WAP find and replace a character in a string. 2. WA function to perform the substraction of two .Eg:char N1="123",N2="478",N3=-355(N1-N2). 3. WAP dynamically intialize a 2 dimentional array Eg:5x20,accept strings and check for vowels and display the no.finally free the space allocated . 4. WAP read a line from file from location N1 to N2 using command line agruments Eg:exe 10 20 a.c 5. WAP find the largest of 4 no using macros. General section Computer science general, c/c++ section, Java section ,The question paper had 48 questions to be answered in 1hr. Time will be quite sufficient. They have different sets of question papers. . 1 General section : computer science general knowledge 2. Computer science general: simple questions

Upload: priyanka

Post on 12-Nov-2014

1.630 views

Category:

Documents


0 download

TRANSCRIPT

Page 1: HP Placement Paper

HP Placement Papers and Sample PapersThe test comprises of 4 sections: Section A. ------50qns(general appitude,english etc):

Section B. ------ 10 Questions on Computer concepts.

Section C. ------ 30 Questions on C

1. WAP find and replace a character in a string.2. WA function to perform the substraction of two .Eg:char N1="123",N2="478",N3=-355(N1-N2).3. WAP dynamically intialize a 2 dimentional array Eg:5x20,accept strings and check for vowels and display the no.finally free the space allocated .4. WAP read a line from file from location N1 to N2 using command line agruments Eg:exe 10 20 a.c 5. WAP find the largest of 4 no using macros.

General section

Computer science general, c/c++ section, Java section ,The question paper had 48 questions tobe answered in 1hr. Time will be quite sufficient. They have different sets of question papers. .

1 General section : computer science general knowledge

2. Computer science general: simple questions

1. HP acquired this company in 2002. Which is the companya) Compaq b) Dell c) option 3 d) Option4Ans: a

2. What does 3G denotea) 3rd generation mobile communication b) 3rd generation computer languages c) option 3 d) option4Ans: a

Page 2: HP Placement Paper

3. An application program that is used by the users to get the inofrmation from the backend of someapplication like databases:a) application server b)proxy server c)database server d)option 4Ans: database server

4. Which of the following is not true about the e-maila) It can be accessed by a client program using POPb) It can be accessed by a client program using imap protocolc) option 3d) option 4Ans: I don't remember the answer but first 2 are true.

5. Some quesion regarding the company and who developed it ( the thing to remember is that Appleproduce Macintosh computers).

c/c++ section: questions on c/c++, programs o/p etc.

1 main( ){unsigned int i=3; while( i >=0)printf( "%d", i--);}how many times will the printf stmt be executed?a)0 b)3 c)4 d)infiniteAns: I think the answer is infinite, b'cos 'i' is an unsigned integer and it will not decrement below '0'and hence end up in an infinite loop.(yes, i checked and it is getting stuck in an infinite loop)

2. main( ){int x,y, z;x=2;y=5;z= x+++y;printf("%d %d %d", x, y z);}a)3 5 7 b)option 2 c)option 3 d)option 4Ans: a

Page 3: HP Placement Paper

3 # define swap(a,b) temp=a; a=b; b=temp;main( ){ int i, j, temp;i=5;j=10;temp=0;if( i > j)swap( i, j );printf( "%d %d %d", i, j, temp);}Ans: On compiling i got ans 10, 0, 0. I did not understand the concept. Please expalin this to me.

4. Java section: questions on java related stuff.1) Java was initially code named as:a)Oak b)green c)miller d)option4Ans: Oak

5. What is not true about the following statements about java. a) it is compiled using javac compilerb) the compiled files have .class extension.c) such files cannot be transfered from one comp to another.d) they use the java interpreter Ans: c

6. Why is the synchronize used?a) to initialize multiple objects b)to lock an object c)option3 d)option 4Ans: b (probably)

C   And C++

1.

i=23, j=4, c=0;

c=i++-++j;

o/p?

Page 4: HP Placement Paper

2.

#define CUBE(x)     x*x*x

#define MUL3(x,y) 3*x*y

#define ADD(x)       x+y

some statement maikng use of the preprocessors defined above............find o/p.

3.

virtual destructors r used  for ?

4.

2 questions on friend functions & classes

5.

char c[]="123456789";

 i=4;

printf("%c %c", c[i], i[c]);

o/p?

one more question on these lines.

6.

int *ptr;

 p=0;

Page 5: HP Placement Paper

 p++;

 printf("%u", p);

 o/p?

a. 0  b. garbage value  c. 4  d. none of the above

7.

double i=0.0;

 switch(i)

    {

      case 0.0: 

      printf("jgdj");

      case 1.0:

      printf("ptoy");

             break;

    default:

           printf("hdfv");

}

o/p?

8.

volatile int i;

in d above statement, is "volatile"

a. a type declaration b. type qualifier c. storage class d. none of the above

                        Unix

Page 6: HP Placement Paper

1.

"bash" is a kind of shell in UNIX

2.

primitive flavours of unix

options : a. BSD &Sys V b. LINUX & BSD c..

3.

which of the folllowing is used 4 redirection in UNIX?      >, |, <, ^

4.

wot is d UNIX terminology 4 multi-tasking?

a. time slicing b. pre-emptive ....... c. time division d.......

5.

In UNIX if You try accessing a directory  for which u dont have permission, wot

message is displayed?

a. permission denied   b. invalid user    c. access denied   d.........

Page 7: HP Placement Paper

C++ was developed by Bjarne Stroustrup of AT&T Bell Laboratories in the early 1980's, and is based on the C language. The name is a pun - "++" is a syntactic construct used in C (to increment a variable), and C++ is intended as an incremental improvement of C. Most of C is a subset of C++, so that most C programs can be compiled (i.e. converted into a series of low-level instructions that the computer can execute directly) using a C++ compiler.The American National Standards Institution (ANSI) provides "official" and generally accepted standard definitions of many programming languages, including C and C++. Such standards are important. A program written only in ANSI C++ is guaranteed to run on any computer whose supporting software conforms to the ANSI standard. In other words, the standard guarantees that ANSI C++ programs are portable. In practice most versions of C++ include ANSI C++ as a core language, but also include extra machine-dependent features to allow smooth interaction with different computers' operating systems.

IBM Campus Placement Paper 2009 (Technical-C C++, Aptitude)

1.Difference between 123 and O123 in c language

2.The command used to count the number of lines in UNIX:

3.The commands like cat, date are stored in___________ directory:a)/dev,b)/temp,c)/prog

4.The attribute of one table is used as the key address of another table. this kind of address is calleda) foreign addressb) primary addressc) secondary address

5.A container contains pure milk. if 20% is replaced by water and then the same processes is repeated twice then what will b the % of milk remaining?

6.A can fill a tank in 6 hours and B can fill the tank in 4 hours. if both the pipes are opened alternatively for an hour with A as the first then in how many hours will the tank b filled?

7.In 50 coins 1 is defective (more weight) .in how many weighs can u find the defective coin?

8.In a km race A beats B by 28metres or 7 sec. find A’s time over the course?

9.A frog can climb a distance of 12m and then falls back by 5m. in how much time will it climb

Page 8: HP Placement Paper

a well of 63m?

10.If a square piece is cut into 27 parts in 6 cuts and is coated with cake in all its outer surfaces than find the number of pieces without cake?

11.the number of multiplications done in square matrix of order n?

12.If 1st Jan is a Sunday then find the number of Sundays in that year?

13.If there r 20 black and 20 white socks, then find the number of chances which will help to collect three pair of socks?

14.There r 180 coins totally comprising of 10p and 25p coins. contributing to 36.90 rs. Find the number of 10p coins?

15.there r three persons A,B,C.out of which one says always the truth. other 2 always speaks false. each one makes a statement?1.i am not A2.I am not B.3.I am C.

16.int cwhile(c!=getchar()!=#)putchar();} if the input is ABCD# ,what will b the output?

17.Inline function is used for?

18.comment:

{float a,b,c;if(b*b-4*a*c)=0.0printf(“the roots r equal”);}

19.int x=14,y=10,z=3;x*=y+1+z;printf(“%d”,x);}what is the value of x

20.40% of the people read newspaper A,50% B,10% both A&B. how many % doesn't read any of the both?

21.relation between class and structure…(something like public ,private..)

Page 9: HP Placement Paper

22.which operator cannot be overloaded? ?:

23.which of the given statements is true ‘but overloading?

24.If a flight ticket is to be booked and attributes like flight number, ticket number,destination,arrival,sat number are given. which of the above is the primary key?

25) If one man do a job of two boys. If 12 men’s and 15 boys can do a work in 25 days working 7.5 hrs a day. How many boys are required along with 21 men’s to complete a work twice the first one in 50 days.

26) If 200m and 150m long trains moving in the same direction at a speed of 40kmph and 45kmph, what is the time taken by the trains to cross each other.

27. If the radius of the circle is decreased by 50% then the area will be reduced by what percentage. Ans 25%

28) If average age of a five member group is same as three years ago. When a old man is replaced by a young man. What is the diff. between their ages.

29) 3 step of a ladder is immersed in water .if thickness of the steps is 1.5” and distance between the steps is 8” .the tide raise at the rate of 16” per hour for first 6 hrs and then it ebbs at the rate of 8” per hour .after 8 hrs how many steps will be immersed in water.

Section A:

1. Which of the following involves context switch,

(a) system call(b) privileged instruction(c) floating point exception(d) all the above(e) none of the above

Ans: (a)

2. In OST, terminal emulation is done in

(a) sessions layer(b) application layer(c) presentation layer(d) transport layer

Page 10: HP Placement Paper

Ans: (b)

3. For a 25MHz processor , what is the time taken by the instruction which needs 3 clock cycles,

(a)120 nano secs(b)120 micro secs(c)75 nano secs(d)75 micro secs

4. For 1 MB memory, the number of address lines required,

(a)11(b)16(c)22(d) 24

Ans. (b)

5. Semaphore is used for

(a) synchronization(b) dead-lock avoidence(c) box(d) none

Ans. (a)

6. Which holds true for the following statement

class c: public A, public B

a) 2 member in class A, B should not have same nameb) 2 member in class A, C should not have same namec) bothd) none

Ans. (a)

Page 11: HP Placement Paper

7. Question related to java

8. OLE is used in

a) inter connection in unixb) interconnection in WINDOWSc) interconnection in WINDOWS NT

9. Convert a given HEX number to OCTAL

10. Macros and function are related in what aspect?

(a)recursion(b)varying no of arguments(c)hypochecking(d)type declaration

11.Preproconia.. does not do which one of the following

(a) macro(b) conditional compliclation(c) in type checking(d) including load file

Ans. (c)

12. Piggy backing is a technique for

a) Flow controlb) Sequencec) Acknowledgementd) retransmission

Ans. (c)

13. In signed magnitude notation what is the minimum value that can be represented with 8 bits

(a) -128(b) -255(c) -127

Page 12: HP Placement Paper

(d) 0

14. There is an employer table with key fields as employer number data in every n'th row are needed for a simple following queries will get required results.

(a) select A employee number from employee A , where exists from employee B where A employee no. >= B employee having (count(*) mod n)=0(b) select employee number from employe A, employe B where A employe number>=B employ number group by employee number having(count(*) mod n=0 )(c) both (a) & (b)(d) none of the above

15. Type duplicates of a row in a table customer with non uniform key field customer number you can see

a) delete from costomer where customer number exists( select distinct customer number from customer having count )b) delete customer a where customer number in b rowidc) delete customer a where custermor number in( select customer number from customer a, customer b )d) none of the above

Section B

1. Given the following statementenum day = { jan = 1 ,feb=4, april, may}What is the value of may?

(a) 4(b) 5(c) 6(d) 11(e) None of the above

2. Find the output for the following C program

main{int x,j,k;j=k=6;x=2;x=j*k;printf("%d", x);

Page 13: HP Placement Paper

3. Find the output for the following C program

fn f(x){ if(x<=0)return;else f(x-1)+x;}

4. Find the output for the following C program

i=20,k=0;for(j=1;j{k+=j<10?4:3;}printf("%d", k);

Ans. k=4

5. Find the output for the following C program

int i =10main(){int i =20,n;for(n=0;n<=i;){int i=10;i++;}printf("%d", i);

Ans. i=20

6. Find the output for the following C program

int x=5;y= x&y

Page 14: HP Placement Paper

7.Find the output for the following C program

Y=10;if( Y++>9 && Y++!=10 && Y++>10){printf("%d", Y);elseprintf("%d", Y);}

Ans. 13

8. Find the output for the following C program

f=(x>y)?x:y

a) f points to max of x and yb) f points to min of x and yc)error

Ans. (a)

9. What is the sizeof(long int)

(a) 4 bytes(b) 2 bytes(c) compiler dependent(d) 8 bytes

10. Which of the function operator cannot be over loaded

(a) <=(b) ?:(c) ==(d) *

11. Find the output for the following C program

main(){intx=2,y=6,z=6;

Page 15: HP Placement Paper

x=y==z;printf(%d",x)}

Section C (Programming Skills)

1.Answer the questions based on the following program

STRUCT DOUBLELIST{ DOUBLE CLINKEDINT DET; LIST VOIDSTRUCT PREVIOUS; (BE GIVEN AND A PROCEDURE TO DELETE)STRUCT NEW; (AN ELEMENT WILL BE GIVEN)}DELETE(STRUCT NODE){NODE-PREV-NEXT NODE-NEXT;NODE-NEXT-PREV NODE-PREV;IF(NODE==HEAD)NODE}

Q. In what case the prev was

(a) All cases(b) It does not work for the last element(c) It does not for the first element(d) None of these

2.Answer the questions based on the following program

VOID FUNCTION(INT KK){KK+=20;}VOID FUNCTION (INT K)INT MM,N=&MKN = KKN+-=10;}

Page 16: HP Placement Paper

Q. What is the output of the following program

main(){ int var=25,varp;varp=&var;varp p = 10;fnc(varp)printf("%d%d,var,varp);}

(a) 20,55(b) 35,35(c) 25,25(d)55,55

Section D

1. a=2, b=3, c=6 Find the value of c/(a+b)-(a+b)/c

2. What does the hexanumber E78 in radix 7.

(a) 12455(b) 14153(c) 14256(d) 13541(e) 131112

Ans. (d)

3. 10 : 4 seconds :: ? : 6 minutes

Ans. 900

4. Q is not equal to zero and k = (Q x n - s)/2.What is n?

(a) (2 x k + s)/Q(b) (2 x s x k)/Q(c) (2 x k - s)/Q(d) (2 x k + s x Q)/Q(e) (k + s)/Q

Page 17: HP Placement Paper

5. From the following statements determine the order of ranking

M has double the amount as D, Y has 3 rupees more than half the amount of DAns. Data insufficient

Questions 6 - 10 are to be answered on the following data

A causes B or C, but not bothF occurs only if B occursD occurs if B or C occursE occurs only if C occursJ occurs only if E or F occursD causes G,H or bothH occurs if E occursG occurs if F occurs

6. If A occurs which of the following must occurs

I. F and GII. E and HIII. D

(a) I only(b) II only(c) III only(d) I,II, & III(e) I & II (or) II & III but not both

Ans. (e)

7. If B occurs which must occur

(a) D(b) D and G(c) G and H(d) F and G(e) J

Ans. (a)

Page 18: HP Placement Paper

8. If J occurs which must have occured

(a) E(b) either B or C(c) both E & F(d) B(e) both B & C

Ans. (b)

9. Which may occurs as a result of cause not mentioned

I. DII. AIII. F

(a) I only(b) II only(c) I & II(d) II & III(e) I,II & III

Ans. (c)

10. E occurs which one cannot occurs

(a) A(b) F(c) D(d) C(e) J

Ans. (b)

1. What do you mean by pure virtual functions?

Page 19: HP Placement Paper

2. inheritance

3. What is function overriding?

4. Dangers of public unsigned, diamond-shaped inheritance

5. What does this function do:

6. What was the most difficult debug you have ever done?

7. What is the difference between Object and Instance?

8. Explain how static class member initialized?

9. what is the difference between block structured language and highly block structured language

10. What is the diffrence between static_cast and dynamic_cast in RTTI

11. how is static variable stored in the memory?( if there are 2 functions in a file,and the static variable name is same (ex var) in both the function. how is it keep seperately in the memory).

12. what is an escaping variable

13. How can you force instantiation of a template?

14Design a class for car inventory . For every new car from the manufacturer there should be minimal changes to the code.

15. What are the advantages of using Doc/View or SDI over DialogBox

16. hat is framework in C++?A framework is a collection of classes and applications, libraries of

Page 20: HP Placement Paper

SDKs and APIs to help the different components all work together

17. What happens to the member function in the class when copy constructor is invoked?

18. what is the difference between obeject oriented programing langauge and structure oriented programing langauge

19. polymorphism

20. what is difference between visual c++ & ANSI c++ ? 21. What are the different types of Storage classes?

22. What is proper and improper inheritance? Explain with an example?

23. How will you detect if there is memory leak in your C++ program?

24. What is the difference between function overloading and operator overloading?

25. What is the difference between char str, char *str and char* str ?Explain the meaning of char* or int* ?

26. What is the compilation difference at the compiler level for C++, VC++ and C# ?

27. What is virtual constructors/destructors?

28. Is there any way to write a class such that no class can be inherited from it. Please include code

29. What is the difference between structures and classes in C++?

30. Difference between Frame, view, document in VC++

Page 21: HP Placement Paper

31. What is the difference between far pointer and near pointer?

32. Explain why encapsulation is required?

33. What is the difference between macro and inline()?

34. What are Virtual Functions? How to implement virtual functions in "C"

35. What is namespace?

36. What is the difference between class and structure?

37. What is the difference between an object and a class?

38. Why the size of empty Class is one byte?

39. how do you run watch with standard input by keyboard

40. What is friend function? 41. What is the difference between static global variable and static local variable?

42. Why Pointers are not used in C Language. What are the main differences between C and C++

43. Why an empty Structure will occupy 2Bytes in C++

44. How do you calculate mode from an array of integers?

45. What are the disadvantages of C++?

Page 22: HP Placement Paper

46. What is the difference between user defined object and Standard object?

47. what is the difference between function templates and function overloading?

48. What are anonymous structure, unions and what are their uses?

49. What is a fake pointer?

50. What is the use of new operator? 51. While copying the objects if we say X a=b, X a(b) What will it call, assignment operator or copy constructor? Justify

52. The company pays a sales person on a commission basis. The sales person receives $200 per week plus 9 % of their gross salary for that week. For ex. if sales person who grosses 5000$ then he paid $650($200+$450). Write a prog in C++ (using array of counter) that determine how many of the sales person earned salaries in each of following ranges (assume that each sales person salary is truncated to an integer amount) :a. $200-$299 b. $300-$399 so on..i. $1000 and over

53. What is abstraction?

54. What is the output of printf ("%d")

55. VTable is same for all objects of class. That means it is stored in memory . Can we obtain the address of VTable without creating any object of class?

56. what is the difference between c&c++?

57. what is the difference betwen wait() and delay()?

58. What is "strstream��

Page 23: HP Placement Paper

59. What is a class?

60. What is document view architecture in VC++

61. the following code results in class eg { void ml( ) {int i = 6; for {int i=5: i< 10;i ++ } { if{i==6} continue; system.out.println {i} ; } } ; } 1. syntax / compilation error 2. 5 6 7 8 9 3. 6 7 8 9 4. 5 7 8 9

62. What is Smart Pointer?

63. Suppose there is a txt file with following format:Student name Grades in subjectsX ABA+CDA+Y B+CAA+AAthere can be many students with there grades in various subjects. (number of subjects are unknown)Possible values of grade are: A, A+, B, B+, C, D now suppose the file gets corrupted and all '+' are replaced by 'A'Write a program to restore the file

64. Can we use static variables in file2 if they are defined in file1 ? If yes, then how ?

65. I want C++ code forCreate method inside Principal mentor class called assignAssociates to assign associate mentors from faculty.txt to a course. Create a file named associates.txt store CourseId,FacultyId,Role. Overload assignAssociates function with arguments. Overloading Method1 with three arguments courseId,FacultyId,Role. Overloading Method2 with two arguments courseId,FacultyId. ( Section 6.17 from chapter 6. ) Overload methods compactly and conveniently by using function templates. Crea

66. what is importance of const. pointer in copy constructor?

67. How to create an object such that it should not call constructor by default.

68. What are Polymorphic Classes?

69. What are inline functions?

Page 24: HP Placement Paper

70. Difference between a "assignment operator" and a "copy constructor" 71. what is defference between constructor and destructor

72. What errors are caught at compile time vs link time?

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

74. What are the types of STL containers?

75. What is public, protected, private?

76. What is the difference between Function and Member function? 77. it possible to inherit the private member in drived class?

78. How can double dimensional arrays be dynamically initialized in C++?

79. what is memory leaking in c++ ?

80. What is an object? 81. What is virtual class and friend class?

82. What do you mean by binding of data and functions?

83. What is function overloading and operator overloading?

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

85. What do you mean by inline function?

Page 25: HP Placement Paper

86. What is RTTI?

87. What happens to the member pointers when an exception occures in constructor, while allocating memory ? how can we over come this ?

88. 1.why constructor can't be virtual?2.what's the difference between destuctor and virtual destructor?

89. What is difference between followin intialization.int iVar1;int iVar2 = int();and which one of two should we prefer always and why?

90. What is difference between Constant Object and Constant variable

91. What is the difference between realloc() and free()

92. what is virtual base class?

93. How many parameters can be passed to a function in c++ ?

94. What is the use of constructor?

95. What is structure padding.Describe briefly?

96. Is Templates also a type of Static Polymorphism?

97. what are proxy objectives

98. can destructor be private?

Page 26: HP Placement Paper

99. what is the difference b/w get() and getline().

100. Why cant one make an object of abstract class?Give compiler view of statement 101. Difference between "C structure" and "C++ structure".

102. Why size of an empty function is 5?

103. How copy constructor works?

104. What is difference between object oriented programing language and structure oriented programing?

105. What is difference between inline function and ordinary function?

106. How to use methods for object in C#, other than built in methods like gettype(), gethashcode()?

107. Class X{X(){}X(X &obj){} // supose '=' operator is also overloaded for this class. I am not writing code for that }main(){X a;X b = a;X c(&a);X d;d = a;}What is the difference between a, b, c, d objects ?

108. Find nth node from end of a singly linked list

109. Write a program to dynamically create a matrix( no of rows and columns wud be provided by user at run time). Then ask a user to input elements and the nprint those elements.

110. Under which conditions compiler provide default constructor to an object when no default constructor is defined in the class definition? 111. What are the things contains in .obj file ? ( compiled result of .cpp file )

112. What is the Basic nature of "cin" and "cout" and what concept or principle we are using on those two?

113. how to create an object for a class that hasa constructor defined under privete access specifier

114. How do you write a program which produces its own source code as its output?

115. can you allocate the memory using malloc() in C and deallocate the same memory using free() in c+

Page 27: HP Placement Paper

+

116. without using function overloading how can do the same job?

117. What is encapsulation?

118. what is the use of virtual destructor?

119. Can main() be overridden

120. can we take "main function" as of type float,char etc?

121. what will be output of the following code#includeusing namespace std;class abc{ public : void main() { cout

122hey anybody help me to write code for this programwap which display year,month & day presents in a year for eg.1. no. is 14 print 2 weeks2. no is 90 print 3 months3. no is 365 print 1 yearuser can input any no

123. what is the use of volatile keyword? Give me one example?

124. Why cann't we overload the sizeof, :?, :: ., .* operators in c++

125. why array index starts from 0[zero] only?

126. Explain the need for "Virtual Destructor".

127. what is difference between copy constructor and constructor?

128. What is operator overloading?what r the advantages of operator overloading?

129. What is a memory leak? How can we avoid it?

Page 28: HP Placement Paper

130. What is an iterator?

Previou131. what are auto static variables and auto extern variables?

132. Define copy constructor? What is the use of copy constructor?

133. What is a template?

134. What is the need /use of function overloading

135. class A(){};int main(){ A a;}Whether there will be a default contructor provided by the compiler in above case ?

136. What is a "RTTI"?

137. Have you heard of "mutable" keyword?

138. Why always array starts with index 0

139. What is polymorphism? Explain with an example?

140. What do you mean by inheritance? 141. What are the different types of polymorphism?

142. Difference between "vector" and "array"?

143. How to write a program such that it will delete itself after execution?

Page 29: HP Placement Paper

144. What is the difference between "overloading" and "overriding"?

145Explain "passing by value", "passing by pointer" and "passing by reference"

146. Can we have "Virtual Constructors"?

147. How can we define a dynamic memory allocation in UNIX operating system?

148. 1.different types of languages compare in c++ and other lanuages2.oops concepts in other language oops

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

150. What is Namespace? 151. In c++ have a default constructor ?

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

153. Can we generate a C++ source code from the binary file?

154. What will happen if I say delete this

155. How can you force instantiation of a template?

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

157. What are virtual functions?

158. What is placement new?

Page 30: HP Placement Paper

159. we can overload assignment operator as a normal function.But we can not overload assignment operator as friend function why?

160. What is a scope resolution operator?

1. What does static variable mean? 2. What is a pointer? 3. What is a structure? 4. What are the differences between structures and arrays? 5. In header files whether functions are declared or defined? 6. What are the differences between malloc() and calloc()? 7. What are macros? What are the advantages and disadvantages? 8. Difference between pass by reference and pass by value? 9. What is static identifier? 10. Where are the auto variables stored? 11. Where does global, static, local, register variables, free memory and C Program instructions get stored? 12. Difference between arrays and linked list? 13. What are enumerations? 14. Describe about storage allocation and scope of global, extern, static, local and register variables? 15. What are register variables? What are the advantage of using register variables? 16. What is the use of typedef? 17. Can we specify variable field width in a scanf() format string? If possible how? 18. Out of fgets() and gets() which function is safe to use and why? 19. Difference between strdup and strcpy? 20. What is recursion? 21. Differentiate between a for loop and a while loop? What are it uses? 22. What are the different storage classes in C? 23. Write down the equivalent pointer expression for referring the same element a[i][j][k][l]? 24. What is difference between Structure and Unions? 25. What the advantages of using Unions? 26. What are the advantages of using pointers in a program? 27. What is the difference between Strings and Arrays? 28. In a header file whether functions are declared or defined? 29. What is a far pointer? where we use it? 30. How will you declare an array of three function pointers where each function receives two ints and returns a float? 31. What is a NULL Pointer? Whether it is same as an uninitialized pointer? 32. What is a NULL Macro? What is the difference between a NULL Pointer and a NULL Macro?

Page 31: HP Placement Paper

33. What does the error ‘Null Pointer Assignment’ mean and what causes this error? 34. What is near, far and huge pointers? How many bytes are occupied by them? 35. How would you obtain segment and offset addresses from a far address of a memory location? 36. Are the expressions arr and *arr same for an array of integers? 37. Does mentioning the array name gives the base address in all the contexts? 38. Explain one method to process an entire string as one unit? 39. What is the similarity between a Structure, Union and enumeration? 40. Can a Structure contain a Pointer to itself? 41. How can we check whether the contents of two structure variables are same or not? 42. How are Structure passing and returning implemented by the complier? 43. How can we read/write Structures from/to data files? 44. What is the difference between an enumeration and a set of pre-processor # defines? 45. What do the ‘c’ and ‘v’ in argc and argv stand for? 46. Are the variables argc and argv are local to main? 47. What is the maximum combined length of command line arguments including the space between adjacent arguments? 48. If we want that any wildcard characters in the command line arguments should be appropriately expanded, are we required to make any special provision? If yes, which? 49. Does there exist any way to make the command line arguments available to other functions without passing them as arguments to the function? 50. What are bit fields? What is the use of bit fields in a Structure declaration? 51. To which numbering system can the binary number 1101100100111100 be easily converted to? 52. Which bit wise operator is suitable for checking whether a particular bit is on or off? 53. Which bit wise operator is suitable for turning off a particular bit in a number? 54. Which bit wise operator is suitable for putting on a particular bit in a number? 55. Which bit wise operator is suitable for checking whether a particular bit is on or off? 56. Which one is equivalent to multiplying by 2? o Left shifting a number by 1 o Left shifting an unsigned int or char by 1? 57. Write a program to compare two strings without using the strcmp() function. 58. Write a program to concatenate two strings. 59. Write a program to interchange 2 variables without using the third one. 60. Write programs for String Reversal. The same for Palindrome check. 61. Write a program to find the Factorial of a number. 62. Write a program to generate the Fibonacci Series? 63. Write a program which employs Recursion? 64. Write a program which uses command line arguments. 65. Write a program which uses functions like strcmp(), strcpy(), etc. 66. What are the advantages of using typedef in a program? 67. How would you dynamically allocate a one-dimensional and two-dimensional array of integers? 68. How can you increase the size of a dynamically allocated array? 69. How can you increase the size of a statically allocated array?

Page 32: HP Placement Paper

70. When reallocating memory if any other pointers point into the same piece of memory do you have to readjust these other pointers or do they get readjusted automatically? 71. Which function should be used to free the memory allocated by calloc()? 72. How much maximum can you allocate in a single call to malloc()? 73. Can you dynamically allocate arrays in expanded memory? 74. What is object file? How can you access object file? 75. Which header file should you include if you are to develop a function which can accept variable number of arguments? 76. Can you write a function similar to printf()? 77. How can a called function determine the number of arguments that have been passed to it? 78. Can there be at least some solution to determine the number of arguments passed to a variable argument list function? 79. How do you declare the following: o An array of three pointers to chars o An array of three char pointers o A pointer to array of three chars o A pointer to function which receives an int pointer and returns a float pointer o A pointer to a function which receives nothing and returns nothing 80. What do the functions atoi(), itoa() and gcvt() do? 81. Does there exist any other function which can be used to convert an integer or a float to a string? 82. How would you use qsort() function to sort an array of structures? 83. How would you use qsort() function to sort the name stored in an array of pointers to string? 84. How would you use bsearch() function to search a name stored in array of pointers to string? 85. How would you use the functions sin(), pow(), sqrt()? 86. How would you use the functions memcpy(), memset(), memmove()? 87. How would you use the functions fseek(), freed(), fwrite() and ftell()? 88. How would you obtain the current time and difference between two times? 89. How would you use the functions randomize() and random()? 90. How would you implement a substr() function that extracts a sub string from a given string? 91. What is the difference between the functions rand(), random(), srand() and randomize()? 92. What is the difference between the functions memmove() and memcpy()? 93. How do you print a string on the printer? 94. Can you use the function fprintf() to display the output on the screen? 95. Gautam Pagedar adds this question: What is a linklist and why do we use it when we have arrays? - I feel the correct answer should be linklist is used in cases where you don’t know the memory required to store a data structure and need to allocate is dynamically on demand. 96. How do you detect a loop in linked list? 97. Sunil asks: What is the difference between main() in C and main() in C++? 98. ajz at his interviews asks what will be printed out when the following code is executed:

Page 33: HP Placement Paper

C++ Interview Questions

1) Contrast and state the difference between visual c++ and ANSI c++?Visual C++ deals with graphical user interface and is the most advanced IDE for creating complex applications. This is used to create real time applications.ANSI C++ is the updated and advanced version than the earlier versions of C++. Libraries and functions are updated in ANSI C++ compared to the earlier versions.

2) State the difference between the structure for C and C++?The main difference between the structure of C and C++ is, C struct can contain only data and C++ has access limitations and contains functions such as public, private, etc.

3) Define about template in C++ and instantiation?The C++ feature that supports the definition of an object of undetermined type is called a template. Using a template allows the programmer to define the features of the class, while reserving the option of binding the type of the class to the class itself until a class of a particular type is actually needed. The creation of a class of a particular type is called instantiation.

4) Define and explain about the classes in C++ comparing with C?A C++ class builds on the concept of a structure. Whereas a C structure is a collection of named fields, a C++ class is a collection of named fields and methods that apply to objects of that class type. Additionally, the C++ language implements the concept of information hiding, restricting access to certain members of the class to methods of the class itself.

5) Explain about rational class?Rational class contains two data members, numerator and denominator and seven method members, reduce, add, multiply, divide, equal, print, and set rational. The methods in the class Rational explicitly mention only one. This is because the class object for which they are invoked is an implicit parameter for each routine.

6) Explain about Templates in C++?C++ templates are used to optimize code. They are very powerful as they help the program by providing various classes, functions and methods. There is also a disadvantage when we are using C++ templates, they tend to duplicate themselves and get installed which slows down the functioning of the program. This is avoided in Java.

7) Explain Encapsulation and differentiate with regards to C.Encapsulation is an entirely new concept which is present in C++ but not in C. In Encapsulation you can restrict the access of the functions to Public, private and Protected which is not possible in C. It is a general practice among programmers to allow only partial functions which can help in designing to be public while the rest of the code is made into private or protected.

8) Explain multiple inheritances in C++?Multiple inheritances in C++ are a controversial issue. In multiple inheritance a derived class or an unrelated class can obtain function of the base class. In this process it can obtain multiple inheritance. A derived class or unrelated class may obtain more than one base class. This can

Page 34: HP Placement Paper

benefit as well as destroy the structure of the program.

9) Explain about virtual member functions of C++?Virtual member functions come into play when a function belonging to a derived class over rides a base class. This is possible only when there are many similarities in the number of parameters, function definition, object, etc. This increasingly becomes difficult to process during the run time. At this point of time virtual member functions comes to rescue. This overwhelming task is made easy by virtual functions tables.

10) Explain the basic steps to parse a C++ source code?The main difficulty to parse a C++ code lies in the complex definitions of C++ identifiers. They should also satisfy complex scoping rules for C++. Also they should define what type it is and to what type it belongs to. It should also satisfy the basic criteria of parsing source code.

11) Explain about different problems which C++ faces today.The main problem which C++ faces today is because of its large feature set. It is almost similar to C language because of which much of the criticism faced by “C†is faced by C++. It �doesn’t have language features to create multi threaded software. Also this language is unruly compared to modern languages such as Java which has both object oriented and procedural programming.

12) Explain about name spaces?Namespaces help you to group classes, functions, etc under one name which helps you to access it at later stage. To access these name spaces we can use scope operator. During name space naming there arises difficulty when a function uses the same name which causes redefinition errors.

13) Explain about exceptions and its relation to handlers?This function is used for exceptional circumstances and this is made possible by handlers. This exception handler is placed in the code which throws exception and error. This exception throws error when the condition is not satisfied. This handler is placed in a try block in which throw function is present. After the try block a catch function is placed through which exception handlers are declared.

14) Explain about static_cast?Static cast is very helpful for conversions from pointers to related class and also from derived class to base class. This static_cast is also helpful to convert base class to derived class. Static_cast makes sure that atleast classes and objects are completed. This has its disadvantages such as programmer should ensure that the object specified is being moved to its destination.

15) Explain about reinterpret_cast?Reinterpret_cast is platform specific. The code generated for reinterpret_cast is generated for the platform which makes it not useful for inter operability. This transfers pointers, irrespective of classes. This forms a image of the specific class and also pointer pointed or the pointer itself is not checked. This can lead doors to security lapses.

Page 35: HP Placement Paper

16) Explain about explicit conversion within C++ and its supportability?This explicit conversion is required where there is different interpretation on value. There are two different types of explicit conversion such as c like casting and functional. This explicit conversion can be applied indiscriminately on the code which significantly increases errors during run time.

17) Explain about implicit conversion in relation to C++?Implicit conversion does not require any operator for performing its function. It automatically performs when a value is copied to the code. The only exception being, it should be compatible. This allows conversions between bool to numerical types, pointer conversions, and etc. significant runtime errors get reduced with this implicit conversion because it accepts values which are compatible.

18) Explain about the class string stream?This string stream class is defined by a standard header file . This class provides flexibility in converting a string based object to stream. This is useful in extraction and insertion of numerical, strings, characters, etc. This is useful to extract a specific numerical from a string. This also aids in insertion.19) What exactly a data structure performs in C++?A data structure is a collection of data elements under one name. These data elements are collectively known as members and they can have variable lengths and types. Structure_name and object_name are two important types defined in C++. Structure types are defined by structure_name and object_name contains valid identifiers.

20) I am getting an error at runtime for an oversized array but it never shows it as a fault during debugging?In C++ it is very correct syntactically to declare over sized array. It also never shows you any error during compilation but it shows error during run time. The answer lies in pointers. This problem can be mitigated if we can manually specify the memory location by using a reference operator. Automatically pointers assign the variable to a certain location and when it tries to extract during extraction it fails thus creating error.