|
c++ Questions
|
|
07-08-2009, 12:24 PM
(This post was last modified: 07-08-2009 12:39 PM by ravish.)
Post: #1
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
c++ Questions
1.Arithmetic and Assignment Operators
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 2. | When we use void return type? We use it, when the method need not to return a value. A void return type indicates that a method does not return a value |
| 3. | What is an loop Statement? For example:: O/P:: hai |
| 4. |
What do you mean by Swapping variables ? For Example:: int i=india; int j=china; int temp = i; i = j; j = temp; cout << i; Output:: china |
| 6. | What is a class? A class is a programming language construct that is used to group related instant variables and methods. |
| 7. | What is an object? In OOP , an object is an instantiation (implementation) of a class. |
| 8. | What is the difference between an object and a class? A Class is constant one. All of the attributes of a class are fixed before, during, and after the execution of a program. The attributes of a class don't change Objects are created during execution and eventually destroyed. Also during that lifetime, the attributes of the object may undergo significant change. |
| 9. | Differnce between public and Private? Private:: Public:: Private::
|
| 10 | Princeples of OOPS? The 4 principles of OOPS are Abstraction, Ineheritance, Polymorhpism and Encapsulation. Method Overloading and Overriding are a part of the Polymorphism |
| 11 | What is abstraction? Abstraction refers to the act of representing essential features without including the background details. |
| 12 | void main() |
| 13 | main() { char s[ ]="hai"; int i; for(i=0;s[ i ];i++) printf("\n%c%c%c%c",s[ i ],*(s+i),*(i+s),i[s]); } Answer: hhhh aaaa iiii Explanation: s[i], *(i+s), *(s+i), i[s] are all different ways of expressing the same idea. Generally array name is the base address for that array. Here s is the base address. i is the index number/displacement from the base address. So, indirecting it with * is same as s[i]. i[s] may be surprising. But in the case of C it is same as s[i]. |
| 14 | main() { int i=-1,j=-1,k=0,l=2,m; m=i++&&j++&&k++||l++; printf("%d %d %d %d %d",i,j,k,l,m); } Answer: 0 0 1 3 1 Explanation : Logical operations always give a result of 1 or 0 . And also the logical AND (&&) operator has higher priority over the logical OR (||) operator. So the expression ‘i++ && j++ && k++’ is executed first. The result of this expression is 0 (-1 && -1 && 0 = 0). Now the expression is 0 || 2 which evaluates to 1 (because OR operator always gives 1 except for ‘0 || 0’ combination- for which it gives 0). So the value of m is 1. The values of other variables are also incremented by 1. |
| 15 | Difference between function overloading & operator overloading? 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. 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). |
| 16 | Diffrence between Realloc() and Free()? Realloc() is used to reallocate the memory for variable Free() is used to free the allocated memory of a variable |
|
01-05-2010, 12:29 PM
Post: #2
|
|||
|
|||
|
RE: c++ Questions
Hi Ravish,
You have posted such a valuable information. This is very useful to interview and general purpose. r4 card |
|||
|
01-06-2010, 09:55 AM
Post: #3
|
|||
|
|||
|
RE: c++ Questions
thanks yar....
hope u find more such materials in this site
|
|||
|
« Next Oldest | Next Newest »
|





Thank given by