C C And Data Structure Questions

  • June 2020
  • PDF

This document was uploaded by user and they confirmed that they have the permission to share it. If you are author or own the copyright of this book, please report to us by using this DMCA report form. Report DMCA


Overview

Download & View C C And Data Structure Questions as PDF for free.

More details

  • Words: 1,798
  • Pages: 6
Easy Questions C& C++ 1. By default real variable is treated as which type of variable? A: Double 2. Switch is more efficient or if-else? A: Both are almost equal (if conditions are more) Switch is clearer and good way of programming 3. If I don't specify either public or private sections in a class, what is the default? A. In a class, all members are private by default if neither public or private sections are declared. 4. What's the difference between the keywords STRUCT and CLASS? A: The members of a STRUCT are PUBLIC by default, while in CLASS, they default to PRIVATE. They are otherwise functionally equivalent. 5. What is declaration and definition of variable? Declaration: It is giving the type of variable or just creating a variable Ex: int a; Definition: Here space is allocated to the variable and its value isinitialized A=5; 6. What is a friend member function? A. Declaring a friend gives non-members of a class (i.e., other classes) access to the nonpublic members (i.e. private) of a class. 7. What is the "this" pointer? A. "this" is a local variable in the body of a non-static member function. It is a pointer to the object for which the function was invoked. It cannot be used outside of a class member function body. 8. What's the deal with operator overloading? Operator overloading allows C/C++ operators to have user-defined meanings on user-defined types (classes). 9. What operators can/cannot be overloaded? The only C operators that can't be are.(dot operator) and ?:(conditional operator) (and sizeof, which is technically an operator). C++ adds a few of its own operators, most of which can be overloaded except :: (scope resolution) and >(reference operator). 10. What is Namespace? A: It is a feature in C++ to minimize name collisions in the global name space. This namespace keyword assigns a distinct name to a library that allows other libraries to use the same identifier names without creating any name collisions. Furthermore, the compiler uses the namespace signature for differentiating the definitions. 11. Explain "passing by value" and "passing by reference" A: Passing by valuemakes a copy of the variable and can be quite slow and inefficient if the variable is large as a array.

12.

13. 14.

15. 16.

17.

Pass by Reference passes in a reference to a variable - this is effectively the address of the variable into the function. This is considerably more efficient than by value and allows the function to change the variable directly. What is a NULL Pointer? Whether it is same as an uninitialized pointer? A: A null pointer points nowhere; it is not the address of any object or function. A null pointer is conceptually different from an uninitialized pointer. A null pointer is known not to point to any object or function; an uninitialized pointer might point anywhere. What is the use of typedef? A: typedef is a keyword in the C and C++ programming languages. It is used to give a data type a new name. When an object created and what is its lifetime? A: When an class is instantiated the object is created and its lifetime is till the end of the execution of program in normal conditions (free and destructor can be called to delete the object) When will a constructor executed? A: When class is instantiated with new keyword the Constructer is called. Different types of polymorphism in c++ Polymorphism? A: C++ supports two kinds of static (compile-time) and dynamic (run-time) polymorphism. Compile-time polymorphism does not allow for certain run-time decisions, while runtime polymorphism typically incurs a performance penalty. What are the techniques you use for debugging? A: F8 key is used for debugging and F7 is used for tracing Sometimes printf can be used to print and check the values

18. What is the difference between "overloading" and "overriding"? A: Overloading - Two functions having same name and return type, but with different type and/or number of arguments. Overriding - When a function of base class is re-defined in the derived class. 19. What is a dangling pointer? A: The object or variable to which the pointer is referencing is deleted then the pointer is pointing to novalid value. So, it is called Dangling pointer. Def. A dangling pointer arises when you use the address of an object after its lifetime is over. 20. When can you tell that a memory leak will occur? A: When a program exits but the variable (mostly the dynamically allocated) space is not deleted and the space allocated becomes unusable then it is called as Memory Leak Def.A memory leak occurs when a program loses the ability to free a block of dynamically allocated memory.

21. Differentiate between a deep copy and a shallow copy? A: Deep copy involves using the contents of one object to create another instance of the same class. In a deep copy, the two objects may contain the same information but the target object will have its own buffers and resources. The destruction of either object will not affect the remaining object. The overloaded assignment operator would create a deep copy of objects. Shallow copy involves copying the contents of one object into another instance of the same class thus creating a mirror image. Owing to straight copying of references and pointers, the two objects will share the same externally contained contents of the other object to be unpredictable. 22. Describe the main characteristics of static functions. A: The main characteristics of static functions include, • It is without the a this pointer, • It can't directly access the non-static members of its class • It can't be declared const, volatile or virtual. • It doesn't need to be invoked through an object of its class, although for convenience, it may. 23. What does abstract data type means? A: An ADT is a formally specified set of values and associated operations, independent from any particular implementation. ADTs are one of the foundations of OO, because they formalize the notion of "information hiding" or "encapsulation", which hides the implementation of an ADT (i.e., a class) behind its interface. 24. Define Syntax Error Logical Error Runtime Error A: Syntax Error-Errors in coding which arise because syntax is not followed properly. It can occur by human mistake in typing & dueLack knowledge of language. EX - Ram are a boy. Error Correct- Ram is a boy. Logical Error- Here Syntax is correct; program will executeproperly but willnot givecorrect answer. EX- Table is boy syntax correct But meaning is not

Runtime Error- overflow, underflow, out of memory capacity. The exceptions like divide a number by 0 A bit Tricky Questions 25. What is RTTI? In programming, RTTI (Run-Time Type Information or Run-Time Type Identification) refers to a C++ system that keeps information about an object's data type in memory at runtime. Run-time type information can apply to simple data types, such as integers and characters, or to generic objects. This is a C++ implementation of a more generic concept called reflection. 26. Why preincrement operator is faster than post increment? A: Post increment is usually less efficient than preincrement because it has to remember & return its original value 27. Explain working of printf. A: Printf is a Variadic function. Variadic functions are functions which may take a variable number of arguments and are declared with an ellipsis in place of the last parameter. int printf(char *, ...); Uses Var_args to know the variables in the calling function In C these are defined in stdarg.h Programs 28. What is output Float a=0.7 if(0.7>a) printf(“Hello”); else printf(“Hi”); A: Hello Another variation of same question will be if(0.7==a) printf(“Hello”); else printf(“Hi”); A: Hi 29. What is output int i=2 printf(“%d”,++i,++i); A: Error order of evaluation not specified

30. What is output char str[25]=”MAQ Software”; printf(“%s”, &str+2); A: Garbage Value 31. What is the output enumstatus{pass, fail} enum status student1; student1=fail; printf(“%d”,student1); A: 1 32. What is out put main() { char s1[]="hello"; char s2[]="world"; s1=s2; printf("%s",s1); } Compilation error giving it cannot be a modifiable 'lvalue' Data structures 33. Explain about linked list? A: A linked list is a data structure that consists of a sequence of data records such that in each record there is a field that contains a reference (i.e., a link) to the next record in the sequence.

34. Circular Linked List When the last node of liner linked list points to the first node of the list; in that case the list is said to be circular or circularly linked

35. Doubly Linked List In a doubly-linked list, each node contains, besides the next-node link, a second link field pointing to the previous node in the sequence. The two links may be called forward(s) and backwards. Linked lists that lack such pointers are said to be simply linked, or simple linked lists.

36. What are the various kinds of sorting techniques? Which is has best case? A: Bubble sort Quick sort Insertion sort Selection sort Merge sort Heap sort among the sorting algorithms quick sort is the best one 37. Of the following tree structure, which is, efficient considering space and time complexities? a. Incomplete Binary Tree b. Complete Binary Tree c. Full Binary Tree (b) Complete Binary Tree. 38. 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. 39. Which is the simplest file structure? a. Sequential b. Indexed c. Random (a) Sequential 40. 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. 41. 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. 42. In tree construction which is the suitable efficient data structure? (a) Array (b) Linked list (c) Stack (d) Queue (e) none (b) Linked list 43. In RDBMS, what is the efficient data structure used in the internal storage representation? B+ tree. Because in B+ tree, all the data is stored only in leaf nodes, that makes searching easier. This corresponds to the records that shall be stored in leaf nodes.

Related Documents

C,c++ Questions
June 2020 8
C++ Structure
November 2019 24
C Questions And Answers.docx
December 2019 10
C Questions
November 2019 19
C++ Questions
April 2020 8