Skip to main content

Posts

Showing posts from August, 2011

C++/OOPS Interview Questions With Answers - Part IV.

Here, are some sample questions based on "C++/OOPS Programming language". Read it carefully as these questions will help you in cracking any interview. Question - 16) Which header file is required for creating and manipulating data files in C++? Answer: fstream.h Question - 17) What is an access specifier? Answer: An access specifier is a way to specify the scope and accessibility of members of a class. Access specifiers can be either private or protected or public. Question - 18) How is memory allocated to a class and its objects? Answer: When a class is defined, memory is allocated for its member functions and they are stored in the memory. When an object is created, separate memory space is allocated for its data members. All objects work with the one copy of member functions shared by all. Question - 19) What is the difference between an object and a class ? Answer: An object is an identifiable entity with some characteristics and behavior. It r

C++/OOPS Interview Questions With Answers - Part V.

Here, are some sample questions based on "C++/OOPS Programming language". Read it carefully as these questions will help you in cracking any interview. Question - 21) What is polymorphism? Explain with an example ? Answers: Polymorphism is the property by which the same message can be sent to different objects of several different classes, and each object can respond to it in a different way depending upon its class. In C++, polymorphism is implemented through overloading . A function name having several definitions that are differentiable by the number of types of their arguments is known as function overloading. For example, float area (float a) { return a * a; } float area (float a, float b) { return a * b; } Question - 22) What is public, protected and private ? Answers: Public, protected and private are access labels in a class . A class provides three access labels namely private, protected and public. A member declared as public is made avai

C++/OOPS Interview Questions With Answers - VI.

Here, are some sample questions based on "C++/OOPS Programming language". Read it carefully as these questions will help you in cracking any interview. Question - 26) Is prototyping mandatory in C++? Why? Answers: Yes, prototyping is mandatory in C++ . C++ makes it mandatory to ensure proper invocation of functions and prompt error reporting. Question -27) When should a function be made inline? Answers: A function is made inline when: The function is small. The function is not returning any value and contains no return statement. The function does not contain a loop or a switch or a goto. The function does not contain static variables. The function is not recursive. Question - 28) How is a static variable different from a static function? Answers: A static variable has a function scope but the global life time . A static function has a file scope instead of program scope. Question - 29) What is meant by macro? Answers: A macro is a #define f

C++/OOPS Interview Questions And Answers - Part III.

Here, are some sample questions based on "C++/OOPS Programming language". Read it carefully as these questions will help you in cracking any interview. Question - 11) Why ‘char’ is often considered as an integer data type? Answer: The memory implementation of char data type is in terms of the number code, which is an integer. Therefore, it is said to be another integer data type. Question - 12) What is the difference between structure and class in C++? Answer: A structure is a collection of data while the class is a collection of data and functions . Further, all members are public by default in a structure while all members are private by default in class. Class has greater data security than structure. Question - 13) What is the purpose of ios:app? Answer: The function of ios::app is to retain the previous contents of a file and to append to the end of the existing file contents, rather than truncating them. Question -14) What is the purpose of i

C++/OOPS Interview Questions With Answers - Part II.

Here, are some sample questions based on "C++/OOPS Programming language". Read it carefully as these questions will help you in cracking any interview. Question - 6) What is a reference variable ? What is its use ? Answer: A reference variable is an alias name for a previously declared variable. The use of it is that is that the same data object can be referred to by two names and these names can be used interchangeably. Question - 7) What are inline functions ? What is the advantage of using them ? How are they declared ? Answer: An inline function is a function upon which the C++ compiler is asked to perform inline expansion, i.e. the compiler is requested to replace every function call with the complete body of the function, rather than generating the function code at each and every position of the function call. The major advantage of inline functions is that it saves on the overhead of a function call. Since the function is not invoked, but its code is r

C++/OOPS Interview Questions With Answers - Part I.

Here, are some sample questions based on "C++/OOPS Programming language". Read it carefully as these questions will help you in cracking any interview. Question - 1) What is a class? Answer: A class is a group of objects , i.e. data members or member-functions that share common properties and relationships. It represents a group of similar objects. Question - 2) What is an object? Answer: An object is an identifiable entity with some characteristics and behavior. It represents an entity that can store data and its associated functions. Question - 3) List the advantages of object oriented programming? Answer: Object oriented programming has many advantages : Reusability of code. Ease of comprehension. Ease of fabrication and maintenance. Easy redesign and extension. Question - 4) What is meant by ‘call by value’? Answer: In C++, structures can be passed to functions by two methods namely 'by value' and 'by reference'. In 'Ca

C Programming Interview Questions With Answers - Part XV.

129. What Is A Structure? Answer: A structure is a collection of data in which all the declared members are public by default. Data security is limited in structure. The general format of declaration of a structure is: struct { Member1; Member2; ………………. ………………. Member m; } var; 130. What Are The Differences Between A Structure & A Union? Answer: A structure is a collection of data in which all the declared members are public by default. Data security is limited in structure. Union is almost the same as the structure as structure contains members of different data types. In structure, each member has its own memory location whereas members of unions have same memory locations. We can assign values to only one member at a time in union. 131. How Can Typedef Be Used to Define A Type Of Structure? Answer: typedef is used for defining new data types of structures. The general syntax is: typedef type data_name; Here, type is the data type and data_name is

C Programming Interview Questions With Answers - Part XIV.

115. Differentiate Between Pointers & Arrays With Example?  Answer:  Pointers and arrays are very closely linked in C. Consider the following statements: int a[10], x; int *ptr; /* ptr is a pointer variable*/ ptr = &a[0]; /* ptr points to address of a[0] */ x = *ptr; /* x = contents of ptr (a[0] in this case) */ A pointer is a variable so we can do ptr = a and ptr++ ; while an array is not a variable so statements a = pa and a++ are illegal. 116. What Is The Size Of int Pointer, Float Pointer & Char Pointer In C In 32-bit Compiler & 64 bit Compiler? Answer: In a 32 Bit compiler, size of Int Pointer, Char pointer & Float Pointer is 4 bytes and for 64 Bit compiler, size of Int Pointer, Char pointer & Float Pointer is 8 bytes 117. Difference Between An Array Name & A Pointer Variable? Answer: A pointer variable is a variable where as an array name is a fixed address and is not a variable. A pointer variable must be initialized but an ar

C Programming Interview Questions With Answers - Part XIII.

104. What Is A Near Pointer? Answer: A near pointer is 16 bits long. It uses the current content of the CS (code segment) register (if the pointer is pointing to code) or current contents of DS (data segment) register (if the pointer is pointing to data) for the segment part, the offset part is stored in a 16 bit near pointer. Using near pointer limits the data/code to 64KB segment. 105. How Many Bytes Are Occupied By Near, Far & Huge Pointers? Answer: The near pointer is 2 bytes long and far and huge pointers are 4 bytes long. 106. What Are Dangling Pointers? Answer:  Dangling pointer is a concept which results when you have a pointer pointing to a location in memory that is meaningless. For example, consider the function void DanglingPointer(int *x) { int y=0; x = &y; return; } When the function is called, space is allocated for the variable y on the stack, and the pointer x contains the address of that space. But when the function returns control to

C Programming Interview Questions With Answers - Part XII.

93. What Is A Pointer In C? Answer: A pointer in C is a variable. It contains the memory address, i.e, locations of another variable which is declared as the pointer type. 94. What Are The Advantages Of Using Pointers? Answer: Pointers help to save memory spaces. Use of pointer assigns the memory space and also releases it. This helps in making best use of the available memory. In other words, it caters to dynamic memory allocation. With pointers, data manipulation is done with address, so execution becomes faster. Array representation is easy with pointers. 95. Write At Least Three Disadvantages Of A Pointer In C Programming? Answer:  Three important disadvantages of pointers are: Uninitialized pointers might cause segmentation fault and if If pointers are updated with incorrect values, it might lead to memory corruption. Dynamically allocated block needs to be freed explicitly.  Otherwise, it would lead to memory leak. Pointers are slower than

C Programming Interview Questions With Answers - Part XI.

78. How Is Searching In an Arraylist Carried Out? Answer: For searching an element in an array list, first we traverse the array list and with traversing, we compare each element of array with the given element. 79. Where Can An Element Are Inserted In An Array List? Answer: Insertion into an arraylist is possible in three ways: Insertion at the beginning. Insertion at the end. Insertion in between. 80. How Is Deletion In An Array List Carried Out? Answer: Deletion from an array list is possible in three ways: Deletion of the first element. Deletion of the last element. Deletion in between. 81. What Are The Advantages Of Array Lists? Answer: The major advantage of the array list is that we can easily compute the address of the array through index and we can also access the array element through the index. 82. What Are The Disadvantages Of An Array List? Answer: The disadvantage of an array list is that we have to keep the total number of elements and

C Programming Interview Questions With Answers - Part X.

67. What Are The Differences Between Getchar() & Scanf() Functions For Reading Strings? Answer: The getchar() function is used to get a character from the standard input device. While using the getchar() function, there is no need to hit the return key. It is used only with character data types and it can be used to get continuous stream of characters. The scanf() function is used to get input from the standard input device. Here, return key should be typed after each input. It can be used for all data types but continuous stream of inputs is not facilitated. 68. Out Of The Functions fgets() & gets(), Which One Is Safer To Use & Why? Answer: Out of fgets() and gets(), the safer one to use is fgets(). The reason is, gets(), after receiving a string from the input device, gets terminated only when the enter key is pressed. The string can be limitless and it may cause buffer overflow. 69. What Is The Difference Between The Functions strdup() & strcpy()?

C Programming Interview Questions With Answers - Part IX.

60. What Is Recursion? Answer: Recursion is the process of repeating items in a self-similar way. Same applies in programming languages as well where if a programming allows you to call a function inside the same function that is called recursive call of the function as follows: void recursion() { recursion(); /* function calls itself */ } int main() { recursion(); } The C programming language supports recursion, i.e., a function to call itself. But while using recursion, programmers need to be careful to define an exit condition from the function, otherwise it will go in infinite loop. Recursive function is very useful to solve many mathematical problems like to calculate factorial of a number, generating Fibonacci series, etc. 61. A Recursive Procedure Should Have Two Properties. What Are They? Answer: There are two important conditions that must be satisfied by any recursive procedure. They are: There must be some base case where the condition end. Ea

C Programming Interview Questions With Answers - Part VIII.

54. What Is Call By Value In Functions? Answer: Arguments or parameters can be passed to the functions by call by value. In call by value, the values of the variables are passed to the functions. In this, values of variables are not affected by changing the vale of the formal parameter. 55. What Is Call By Reference In Functions? Answer: In Call by reference method of passing arguments to functions, the addresses of the variables are passed. In this, values of variables are affected by changing the value of formal parameters. 56. What Is The Difference Between Call By Value & Call By Reference (Or Pass By Value Or Pass By Reference)? Answer: Call by value means sending the values of the arguments- The value of each of the actual arguments in the calling function is copied into corresponding formal arguments of the called function. The changes made to the formal arguments have no effect on the values of actual arguments in the calling function. This technique of pass