KCC Institute of Technology & Management
Greater Noida (U.P)
TCS Technical Interview Questions
Q1. How is C different from C++?
Answer:
C++ can be said to be a superset of C. Major added features in C++ are Object-Oriented
Programming, Exception Handling and rich C++ Library.
Q2. What is a static variable?
Answer:
Static variables have a property of preserving their value even after they are out of their scope!
Hence, static variables preserve their previous value in their previous scope and are not
initialized again in the new scope.
Q3. Are Variables in C static or Dynamic scoped?
Answer:
Variables in C are always statically scoped.
Q4. Explain the four storage classes in C?
Answer:
Storage Classes are used to describe the features of a variable/function. The four storage
classes in C are:
1. auto: This is the default storage class for all the variables declared inside a function or a
block.
2. extern: Extern storage class simply tells us that the variable is defined elsewhere and not
within the same block where it is used.
3. static:This storage class is used to declare static variables which are popularly used while
writing programs in C language.
4. register: It declares register variables which have the same functionality as that of the auto
variables.
Q5. What do you mean by ‘pass by value’ and ‘pass by reference’?
Answer:
In C we can pass the parameters in a function in two different ways:
Pass by Value: Copy of actual variables is passed in function as a parameter.
Pass by reference: Memory address of actual variables is passed in function as a
parameter.
Q6. What do you mean by macros?
Answer:
Macros are a piece of code in a program which is given some name. Whenever this name is
encountered by the compiler, it replaces the name with the actual piece of code.
Q7. What are structures in C?
Answer:
A structure is a user-defined data type in C/C++. A structure creates a data type that can be
used to group items of possibly different types into a single type.
Questions related to OOPs:
Q8. What are the main concepts of Object Oriented Programming?
Answer:
Object-Oriented Programming or OOPs refers to languages that uses objects in programming.
The main aim of OOP is to bind together the data and the functions that operate on them so
that no other part of the code can access this data except that function.
Main concepts of OOP are:
Polymorphism
Inheritance
Encapsulation
Abstraction
Q9. What are classes and objects?
Answer:
Classes and Objects are two major aspects of Object Oriented Programming:
Class: A class is a user defined blueprint or prototype from which objects are created. It
represents the set of properties or methods that are common to all objects of one type.
Object: An Object is an identifiable entity with some characteristics and behavior. An Object is
an instance of a Class. When a class is defined, no memory is allocated but when it is
instantiated (i.e. an object is created) memory is allocated.
Q10. What are different types of Inheritance?
Answer:
Types of Inheritance:
1. Single inheritance
2. Multiple Inheritance
3. Multi-level Inheritance
4. Hierarchical Inheritance
5. Hybrid Inheritance
Q11. Differentiate Function Overloading and Function Overriding.
Answer:
Function Overloading provides multiple definitions of the function by changing signature i.e
changing the number of parameters, change the data type of parameters, return type doesn’t
play any role whereas Function Overriding is the redefinition of base class function in its
derived class with same signature i.e return type and parameters.
Q12. Give a real-life based implementation of Polymorphism.
Answer:
Real life example of polymorphism, a person at the same time can have different characteristic.
Like a man at the same time is a father, a husband, an employee. So the same person posses
different behavior in different situations. This is called polymorphism.
Q13. What are Access modifiers?
Answer:
Access modifiers are used to implement an important feature of Object-Oriented Programming
known as Data Hiding. Access Modifiers or Access Specifiers in a class are used to set the
accessibility of the class members. That is, it sets some restrictions on the class members not to
get directly accessed by the outside functions.
Q14. Differentiate between a Structure and a Class.
Answer:
A structure is the same as a class except for a few differences. The most important of them is
security. A Structure is not secure and cannot hide its implementation details from the end-user
while a class is secure and can hide its programming and designing details. For more details
see Structure vs Class.
Q15. Can a C++ class have an object of self type?
Answer:
A class declaration can contain a static object of self type, it can also have a pointer to self
type, but it cannot have a non-static object of self type.
Q16. What do you mean by a Friend class and a Friend function?
Answer:
Friend Class: A friend class can access private and protected members of other classes in
which it is declared as a friend. It is sometimes useful to allow a particular class to access
private members of another class.
Friend Function : Like friend class, a friend function can be given special grant to access
private and protected members.
Questions related to Java Programming Language:
Q17. How is Java platform independent?
Answer:
The meaning of platform-independent is that the java compiled code(byte code) can run on all
operating systems. Java codes are compiled and run on JVM and JVM is platform independent
and it is the reason why Java is able to become “Platform Independent”.
Q18. Is main method compulsory in Java?
Answer:
Prior to JDK 7, the main method was not mandatory in a java program. However, from JDK7
main method is mandatory. The compiler will verify first, whether main() is present or not. If
your program doesn’t contain the main method, then you will get an error “main method not
found in the class ”.
Q19. Explain the difference between Interface and a class.
Answer:
A class is a user-defined blueprint or prototype from which objects are created. It represents
the set of properties or methods that are common to all objects of one type while
an interface can also have methods and variables, but the methods declared in an interface are
by default abstract (only method signature, no body). See Interface vs Class in Java.
Q20. How to run java class file which is in different directory?
Answer:
Classpath is the location from where JVM starts execution of a program. Similar to the classic
dynamic loading behavior, when executing Java programs, the Java Virtual Machine finds and
loads classes lazily (it loads the bytecode of a class only when the class is first used). The
classpath tells Java where to look in the filesystem for files defining these classes.
Q21. Why Java is not a purely Object-Oriented Language?
Answer:
Java supports OOPs properties like Encapsulation, Inheritance, Polymorphism, Abstraction,
etc. but it misses on some properties which makes it not a Pure Object Oriented Language.
Q22. How are Java objects stored in memory?
Answer:
In Java, all objects are dynamically allocated on Heap. This is different from C++ where
objects can be allocated memory either on Stack or on Heap.
Q23. What is Null Pointer Exception In Java?
Answer:
NullPointerException is a RuntimeException. In Java, a special null value can be assigned to
an object reference. NullPointerException is thrown when program attempts to use an object
reference that has the null value.
Questions Related to DBMS:
Q24. What is the need of DBMS?
Answer:
A Data Base Management System is a system software for easy, efficient and reliable data
processing and management. It can be used for Creation of a database, Retrieval of information
from the database, Updating the database and Managing a database. There are various
other Needs of a DBMS.
Q25. What is Data Abstraction and Data Independence?
Answer:
Database systems comprise of complex data-structures. In order to make the system efficient in
terms of retrieval of data, and reduce complexity in terms of usability of users, developers use
abstraction i.e. hide irrelevant details from the users. This approach simplifies database design.
The main purpose of data abstraction is achieving data independence in order to save time and
cost required when the database is modified or altered.
Q26. What are interfaces in a DBMS?
Answer:
A database management system (DBMS) interface is a user interface that allows for the
ability to input queries to a database without using the query language itself.
Q27. What is Database Schema?
Answer:
The term “schema” refers to the organization of data as a blueprint of how the database is
constructed (divided into database tables in the case of relational databases). The formal
definition of a database schema is a set of formulas (sentences) called integrity constraints
imposed on a database.
Q28. What is a Foreign key?
Answer:
Foreign Key is a set of attributes in a table which is used to refer the primary key or
alternative key of the same or other tables.
Q29. Difference between Inner Join and Outer Join.
Answer:
An SQL Join is used to combine data from two or more tables, based on a common field
between them.
Q30. Explain ACID properties.
Answer:
ACID stands for Atomicity, Consistency, Isolation, and Durability. In order to maintain
consistency in a database, before and after the transaction, certain properties are followed.
Q31. What is Deadlock in DBMS?
Answer:
In a database, a deadlock is an unwanted situation in which two or more transactions are
waiting indefinitely for one another to give up locks. Deadlock is said to be one of the most
feared complications in DBMS as it brings the whole system to a Halt.
Q32. What is a Nested Query in SQL? Give an example.
Answer:
In nested queries, a query is written inside a query. The result of inner query is used in
execution of outer query.
Questions Related to Data Structures:
Q33. What is a Data Structure?
Answer:
A data structure is a particular way of organizing data in a computer so that it can be used
effectively.
Q34. What is the difference between a Stack and a Queue?
Answer:
A stack is a linear data structure in which elements can be inserted and deleted only from one
side of the list, called the top. A stack follows the LIFO (Last In First Out) principle, i.e., the
element inserted at the last is the first element to come out.
Queue: A queue is a linear data structure in which elements can be inserted only from one
side of the list called rear, and the elements can be deleted only from the other side called the
front. The queue data structure follows the FIFO (First In First Out) principle, i.e. the element
inserted at first in the list, is the first element to be removed from the list.
Q35. What is the difference between a Clustered index and non-clustered index?
Answer:
A clustered index is a special type of index that reorders the way records in the table are
physically stored whereas a non clustered index is a special type of index in which the
logical order of the index does not match the physical stored order of the rows on disk.
Q36. Differentiate between an Array and a Linked List.
Answer:
Both Arrays and Linked List can be used to store linear data of similar types, but they both
have some advantages and disadvantages over each other.
Q37. What is a Doubly Linked List?
Answer:
A Doubly Linked List (DLL) contains an extra pointer, typically called previous pointer,
together with next pointer and data which are there in singly linked list.
Q38. What is a Binary Search Tree?
Answer:
Binary Search Tree, is a node-based binary tree data structure which has the following
properties:
The left subtree of a node contains only nodes with keys lesser than the node’s
key.
The right subtree of a node contains only nodes with keys greater than the node’s
key.
The left and right subtree each must also be a binary search tree.
There must be no duplicate nodes.
Q39. What are the advantages of BST over Hash Table?
Answer:
The time complexity of Search, Insert and Delete operations in a self-balancing Binary Search
Tree (BST) (like Red-Black Tree, AVL Tree, Splay Tree, etc) is O(Logn) whereas Hash
Table supports these operations in O(1) time.
Advantages of Hash Table over BST.
Q40. If you are given two traversal sequences, can you construct the binary tree?
Answer: