Interview Questions
Interview Questions
1) What is C language?
C is known as a mother language because most of the compilers and JVMs are written in C
language. Most of the languages which are developed after C language has borrowed heavily
from it like C++, Python, Rust, javascript, etc. It introduces new core concepts like arrays,
functions, file handling which are used in these languages.
C is called a mid-level programming language because it binds the low level and high -level
programming language. We can use C language as a System programming to develop the
operating system as well as an Application programming to generate menu driven customer
driven billing system.
Dennis Ritchie.
printf(): The printf() function is used to print the integer, character, float and string values on
to the screen.
scanf(): The scanf() function is used to take input from the user.
8) What is the difference between the local variable and global variable in C?
Following are the differences between a local variable and global variable:
Access Variables can be accessed only by those Any statement in the entire
statements inside a function in which program can access variables.
they are declared.
Life Life of a variable is created when the Life of a variable exists until
function block is entered and destroyed the program is executing.
on its exit.
Storage Variables are stored in a stack unless The compiler decides the
specified. storage location of a variable.
o A variable which is declared as static is known as a static variable. The static variable
retains its value between multiple function calls.
o Static variables are used because the scope of the static variable is available in the
entire program. So, we can access a static variable anywhere in the program.
o The static variable is initially initialized to zero. If we update the value of a variable,
then the updated value is assigned.
o The static variable is used as a common value which is shared by all the methods.
o The static variable is initialized only once in the memory heap to reduce the memory
usage.
o C functions are used to avoid the rewriting the same code again and again in our
program.
o C functions can be called any number of times from any place of our program.
o When a program is divided into functions, then any part of our program can easily be
tracked.
o C functions provide the reusability concept, i.e., it breaks the big task into smaller
tasks so that it makes the C program more understandable.
11) What is the difference between call by value and call by reference in C?
Following are the differences between a call by value and call by reference are:
1. #include <stdio.h>
2. void change(int,int);
3. int main()
4. {
5. int a=10,b=20;
6. change(a,b); //calling a function by passing the values of variables.
7. printf("Value of a is: %d",a);
8. printf("\n");
9. printf("Value of b is: %d",b);
10. return 0;
11. }
12. void change(int x,int y)
13. {
14. x=13;
15. y=17;
16. }
Output:
Value of a is: 10
Value of b is: 20
1. #include <stdio.h>
2. void change(int*,int*);
3. int main()
4. {
5. int a=10,b=20;
6. change(&a,&b); // calling a function by passing references of variables.
7. printf("Value of a is: %d",a);
8. printf("\n");
9. printf("Value of b is: %d",b);
10. return 0;
11. }
12. void change(int *x,int *y)
13. {
14. *x=13;
15. *y=17;
16. }
Output:
Value of a is: 13
Value of b is: 17
When a function calls itself, and this process is known as recursion. The function that calls
itself is known as a recursive function.
1. Winding phase
2. Unwinding phase
Winding phase: When the recursive function calls itself, and this phase ends when the
condition is reached.
Unwinding phase: Unwinding phase starts when the condition is reached, and the control
returns to the original call.
Example of recursion
1. #include <stdio.h>
2. int calculate_fact(int);
3. int main()
4. {
5. int n=5,f;
6. f=calculate_fact(n); // calling a function
7. printf("factorial of a number is %d",f);
8. return 0;
9. }
10. int calculate_fact(int a)
11. {
12. if(a==1)
13. {
14. return 1;
15. }
16. else
17. return a*calculate_fact(a-1); //calling a function recursively.
18. }
Output:
Syntax:
1. data_type array_name[size];
o Multidimensional array: Multidimensional array is an array that contains more than
one array.
Syntax:
1. data_type array_name[size];
Example of an array:
1. #include <stdio.h>
2. int main()
3. {
4. int arr[5]={1,2,3,4,5}; //an array consists of five integer values.
5. for(int i=0;i<5;i++)
6. {
7. printf("%d ",arr[i]);
8. }
9. return 0;
10. }
Output:
12345
A pointer is a variable that refers to the address of a value. It makes the code optimized and
makes the performance fast. Whenever a variable is declared inside a program, then the
system allocates some memory to a variable. The memory contains some address number.
The variables that hold this address number is known as the pointer variable.
For example:
1. Data_type *p;
The above syntax tells that p is a pointer variable that holds the address number of a given
data type value.
Example of pointer
1. #include <stdio.h>
2. int main()
3. {
4. int *p; //pointer of type integer.
5. int a=5;
6. p=&a;
7. printf("Address value of 'a' variable is %u",p);
8. return 0;
9. }
Output:
A pointer that doesn't refer to any address of value but NULL is known as a NULL pointer.
When we assign a '0' value to a pointer of any type, then it becomes a Null pointer.
o If a pointer is pointing any memory location, but meanwhile another pointer deletes
the memory occupied by the first pointer while the first pointer still points to that
memory location, the first pointer will be known as a dangling pointer. This problem
is known as a dangling pointer problem.
o Dangling pointer arises when an object is deleted without modifying the value of the
pointer. The pointer points to the deallocated memory.
1. #include<stdio.h>
2. void main()
3. {
4. int *ptr = malloc(constant value); //allocating a memory space.
5. free(ptr); //ptr becomes a dangling pointer.
6. }
In the above example, initially memory is allocated to the pointer variable ptr, and then the
memory is deallocated from the pointer variable. Now, pointer variable, i.e., ptr becomes a
dangling pointer.
The problem of a dangling pointer can be overcome by assigning a NULL value to the
dangling pointer. Let's understand this through an example:
1. #include<stdio.h>
2. void main()
3. {
4. int *ptr = malloc(constant value); //allocating a memory space.
5. free(ptr); //ptr becomes a dangling pointer.
6. ptr=NULL; //Now, ptr is no longer a dangling pointer.
7. }
In the above example, after deallocating the memory from a pointer variable, ptr is assigned
to a NULL value. This means that ptr does not point to any memory location. Therefore, it is
no longer a dangling pointer.
1. #include <stdio.h>
2. int main()
3. {
4. int a=10;
5. int *ptr,**pptr; // *ptr is a pointer and **pptr is a double pointer.
6. ptr=&a;
7. pptr=&ptr;
8. printf("value of a is:%d",a);
9. printf("\n");
10. printf("value of *ptr is : %d",*ptr);
11. printf("\n");
12. printf("value of **pptr is : %d",**pptr);
13. return 0;
14. }
In the above example, pptr is a double pointer pointing to the address of the ptr variable and
ptr points to the address of 'a' variable.
1. For example:
2. int a[10];
The above example creates an array of integer type, and the size of an array is fixed, i.e., 10.
1. For example
2. int *p= malloc(sizeof(int)*10);
22) What functions are used for dynamic memory allocation in C language?
1. malloc()
o The malloc() function is used to allocate the memory during the execution of
the program.
o It does not initialize the memory but carries the garbage value.
o It returns a null pointer if it could not be able to allocate the requested space.
Syntax
1. ptr = (cast-type*) malloc(byte-size) // allocating the memory using malloc() function.
2. calloc()
o The calloc() is same as malloc() function, but the difference only is that it
initializes the memory with zero value.
Syntax
1. ptr = (cast-type*)calloc(n, element-size);// allocating the memory using calloc() functi
on.
2. realloc()
o The realloc() function is used to reallocate the memory to the new size.
o If sufficient space is not available in the memory, then the new block is
allocated to accommodate the existing data.
Syntax
1. ptr = realloc(ptr, newsize); // updating the memory size using realloc() function.
2. free():The free() function releases the memory allocated by either calloc() or malloc()
function.
Syntax
1. free(ptr); // memory is released using free() function.
The above syntax releases the memory from a pointer variable ptr.
calloc() malloc()
Initialization It initializes the content of the It does not initialize the content of
memory to zero. memory, so it carries the garbage
value.
o The structure is a user-defined data type that allows storing multiple types of data in a
single unit. It occupies the sum of the memory of all members.
o The structure members can be accessed only through structure variables.
o Structure variables accessing the same structure but the memory allocated for each
variable will be different.
Syntax of structure
1. struct structure_name
2. {
3. Member_variable1;
4. Member_variable2
5. .
6. .
7. }[structure variables];
Let's see a simple example.
1. #include <stdio.h>
2. struct student
3. {
4. char name[10]; // structure members declaration.
5. int age;
6. }s1; //structure variable
7. int main()
8. {
9. printf("Enter the name");
10. scanf("%s",s1.name);
11. printf("\n");
12. printf("Enter the age");
13. scanf("%d",&s1.age);
14. printf("\n");
15. printf("Name and age of a student: %s,%d",s1.name,s1.age);
16. return 0;
17. }
Output:
o The union is a user-defined data type that allows storing multiple types of data in a
single unit. However, it doesn't occupy the sum of the memory of all members. It
holds the memory of the largest member only.
o In union, we can access only one variable at a time as it allocates one common space
for all the members of a union.
Syntax of union
1. union union_name
2. {
3. Member_variable1;
4. Member_variable2;
5. .
6. .
7. Member_variable n;
8. }[union variables];
1. #include<stdio.h>
2. union data
3. {
4. int a; //union members declaration.
5. float b;
6. char ch;
7. };
8. int main()
9. {
10. union data d; //union variable.
11. d.a=3;
12. d.b=5.6;
13. d.ch='a';
14. printf("value of a is %d",d.a);
15. printf("\n");
16. printf("value of b is %f",d.b);
17. printf("\n");
18. printf("value of ch is %c",d.ch);
19. return 0;
20. }
Output:
value of a is 1085485921
value of b is 5.600022
value of ch is a
In the above example, the value of a and b gets corrupted, and only variable ch shows the
actual output. This is because all the members of a union share the common memory space.
Hence, the variable ch whose value is currently updated.
The sprintf() stands for "string print." The sprintf() function does not print the output on the
console screen. It transfers the data to the buffer. It returns the total number of characters
present in the string.
Syntax
1. int sprintf ( char * str, const char * format, ... );
Output:
value of n is 9
But, if we use #define, we can compile and run a C program without using the main()
function. For example:
1. #include<stdio.h>
2. #define start main
3. void start() {
4. printf("Hello");
5. }
More details.
The Token is an identifier. It can be constant, keyword, string literal, etc. A token is the
smallest individual unit in a program. C has the following tokens:
The argument passed to the main() function while executing the program is known as
command line argument. For example:
1. main(int count, char *args[]){
2. //code to be executed
3. }
The ANSI stands for " American National Standard Institute." It is an organization that
maintains the broad range of disciplines including photographic film, computer languages,
data encoding, mechanical parts, safety and more.
The getch() function reads a single character from the keyboard. It doesn't use any buffer, so
entered data will not be displayed on the output screen.
The getche() function reads a single character from the keyword, but data is displayed on the
output screen. Press Alt+f5 to see the entered character.
1. #include<stdio.h>
2. #include<conio.h>
3. int main()
4. {
5.
6. char ch;
7. printf("Enter a character ");
8. ch=getch(); // taking an user input without printing the value.
9. printf("\nvalue of ch is %c",ch);
10. printf("\nEnter a character again ");
11. ch=getche(); // taking an user input and then displaying it on the screen.
12. printf("\nvalue of ch is %c",ch);
13. return 0;
14. }
Output:
Enter a character
value of ch is a
Enter a character again a
value of ch is a
In the above example, the value entered through a getch() function is not displayed on the
screen while the value entered through a getche() function is displayed on the screen.
33) What is the newline escape sequence?
The new line escape sequence is represented by "\n". It inserts a new line on the output
screen.
34) Who is the main contributor in designing the C language after Dennis Ritchie?
Brain Kernighan.
35) What is the difference between near, far and huge pointers?
A near pointer doesn't have explicit selector whereas far, and huge pointers have explicit
selector. When you perform pointer arithmetic on the far pointer, the selector is not modified,
but in case of a huge pointer, it can be modified.
These are the non-standard keywords and implementation specific. These are irrelevant in a
modern platform.
The typecasting is a process of converting one data type into another is known as typecasting.
If we want to store the floating type value to an int type, then we will convert the data type
into another data type explicitly.
Syntax
1. (type_name) expression;
38) What are the functions to open and close the file in C language?
Yes, by holding the base address of array into a pointer, we can access the array using a
pointer.
A loop running continuously for an indefinite number of times is called the infinite loop.
1. for(;;){
2. //code to be executed
3. }
1. while(1){
2. //code to be executed
3. }
1. do{
2. //code to be executed
3. }while(1);
1. #include<stdio.h>
2. void main(){
3. if(printf("hello world")){} // It prints the ?hello world? on the screen.
}
1) What is OOPS?
1. Abstraction
2. Encapsulation
3. Inheritance
4. Polymorphism
3) What is a class?
A class is simply a representation of a type of object. It is the blueprint/plan/template that
describes the details of an object.
4) What is an Object?
An object is an instance of a class. It has its own state, behavior, and identity.
5) What is Encapsulation?
Encapsulation is an attribute of an object, and it contains all data which is hidden. That
hidden data can be restricted to the members of that class.
6) What is Polymorphism?
Polymorphism is nothing but assigning behavior or value in a subclass to something that was
already declared in the main class. Simply, polymorphism takes more than one form.
7) What is Inheritance?
Inheritance is a concept where one class shares the structure and behavior defined in another
class. If Inheritance applied to one class is called Single Inheritance, and if it depends on
multiple classes, then it is called multiple Inheritance.
Manipulators are the functions which can be used in conjunction with the insertion (<<) and
extraction (>>) operators on an object. Examples are endl and setw.
A constructor is a method used to initialize the state of an object, and it gets invoked at the
time of object creation. Rules for constructor are:
A destructor is a method which is automatically called when the object is made of scope or
destroyed. Destructor name is also same as class name but with the tilde symbol before the
name.
An inline function is a technique used by the compilers and instructs to insert complete body
of the function wherever that function is used in the program source code.
A virtual function is a member function of a class, and its functionality can be overridden in
its derived class. This function can be implemented by using a keyword called virtual, and it
can be given during function declaration.
A virtual function can be declared using a token(virtual) in C++. It can be achieved in
C/Python Language by using function pointers or pointers to function.
A friend function is a friend of a class that is allowed to access to Public, private, or protected
data in that same class. If the function is defined outside the class cannot access such
information.
A friend can be declared anywhere in the class declaration, and it cannot be affected by
access control keywords like private, public, or protected.
Function overloading is a regular function, but it can perform different tasks. It allows the
creation of several methods with the same name which differ from each other by the type of
input and output of the function.
Example
Operator overloading is a function where different operators are applied and depends on the
arguments. Operator,-,* can be used to pass through the function, and it has its own
precedence to execute
An abstract class is a class which cannot be instantiated. Creation of an object is not possible
with an abstract class, but it can be inherited. An abstract class can contain only an Abstract
method. Java allows only abstract method in abstract class while other languages allow non-
abstract method as well.
The ternary operator is said to be an operator which takes three arguments. Arguments and
results are of different data types, and it depends on the function. The ternary operator is also
called a conditional operator.
Finalize method helps to perform cleanup operations on the resources which are not currently
used. Finalize method is protected, and it is accessible only through this class or by a derived
class.
Call by Value – Value passed will get modified only inside the function, and it returns
the same value whatever it is passed into the function.
Call by Reference – Value passed will get modified in both inside and outside the
functions and it returns the same or different value.
20) What is the super keyword?
The super keyword is used to invoke the overridden method, which overrides one of its
superclass methods. This keyword allows to access overridden methods and also to access
hidden members of the superclass.
An exception is an event that occurs during the execution of a program. Exceptions can be of
any type – Runtime exception, Error exceptions. Those exceptions are adequately handled
through exception handling mechanism like try, catch, and throw keywords.
A compiler recognizes a token, and it cannot be broken down into component elements.
Keywords, identifiers, constants, string literals, and operators are examples of tokens.
Even punctuation characters are also considered as tokens. Example: Brackets, Commas,
Braces, and Parentheses.
Overriding is the same method names with the same arguments and return types associated
with the class and its child class.
Abstraction is a useful feature of OOPS, and it shows only the necessary details to the client
of an object. Meaning, it shows only required details for an object, not the inner constructors,
of an object. Example – When you want to switch on the television, it is not necessary to
know the inner circuitry/mechanism needed to switch on the TV. Whatever is required to
switch on TV will be shown by using an abstract class.
Access modifiers determine the scope of the method or variables that can be accessed from
other various objects or classes. There are five types of access modifiers, and they are as
follows:
Private
Protected
Public
Friend
Protected Friend
29) What are sealed modifiers?
Sealed modifiers are the access modifiers where the methods can not inherit it. Sealed
modifiers can also be applied to properties, events, and methods. This modifier cannot be
used to static members.
30) How can we call the base method without creating an instance?
Yes, it is possible to call the base method without creating an instance. And that method
should be “Static method.”
Doing Inheritance from that class.-Use Base Keyword from a derived class.
The new modifier instructs the compiler to use the new implementation instead of the base
class function. Whereas, Override modifier helps to override the base class function.
– Parametric Constructor – With Parameters. Create a new instance of a class and also
passing arguments simultaneously.
THIS pointer refers to the current object of a class. THIS keyword is used as a pointer which
differentiates between the current object with the global object. It refers to the current object.
The default access type of a Structure is public, but class access type is private. A structure is
used for grouping data, whereas a class can be used for grouping data and methods.
Structures are exclusively used for data, and it doesn’t require strict validation, but classes are
used to encapsulate and inherent data, which requires strict validation.
The default access modifier of a class is Internal and the default access modifier of a class
member is Private.
A pure virtual function is a function which can be overridden in the derived class but cannot
be defined. A virtual function can be declared as Pure by using the operator =0.
Example –
Dynamic or Run time polymorphism is also known as method overriding in which call to an
overridden function is resolved during run time, not at the compile time. It means having two
or more methods with the same name, same signature but with different implementation.
This is a special constructor for creating a new object as a copy of an existing object. There
will always be only one copy constructor that can be either defined by the user or the system.
False.
The base class is the most generalized class, and it is said to be a root class.
The superclass is the parent class from which another class inherits.
Binding is nothing but the association of a name with the class. Static Binding is a binding in
which name can be associated with the class during compilation time, and it is also called as
early Binding.
Dynamic Binding is a binding in which name can be associated with the class during
execution time, and it is also called as Late Binding.
Zero instances will be created for an abstract class. In other words, you cannot create an
instance of an Abstract Class.
50) Which OOPS concept exposes only the necessary information to the calling
functions?
Encapsulation
DBMS
1. What is DBMS?
RDBMS stands for Relational Database Management System. RDBMS store the data into the
collection of tables, which is related by common fields between the columns of the table. It
also provides relational operators to manipulate the data stored into the tables.
3. What is SQL?
SQL stands for Structured Query Language , and it is used to communicate with the
Database. This is a standard language used to perform tasks such as retrieval, updation,
insertion and deletion of data from a database.
4. What is a Database?
Database is nothing but an organized form of data for easy access, storing, retrieval and
managing of data. This is also known as structured form of data which can be accessed in
many ways.
A table is a set of data that are organized in a model with Columns and Rows. Columns can
be categorized as vertical, and Rows are horizontal. A table has specified number of column
called fields but can have any number of rows which is called record.
Example:.
Table: Employee.
A primary key is a combination of fields which uniquely specify a row. This is a special kind
of unique key, and it has implicit NOT NULL constraint. It means, Primary key values
cannot be NULL.
A Unique key constraint uniquely identified each record in the database. This provides
uniqueness for the column or set of columns.
A Primary key constraint has automatic unique constraint defined on it. But not, in the case of
Unique Key.
There can be many unique constraint defined per table, but only one Primary key constraint
defined per table.
A foreign key is one table which can be related to the primary key of another table.
Relationship needs to be created between two tables by referencing foreign key with the
primary key of another table.
9. What is a join?
This is a keyword used to query data from more tables based on the relationship between the
fields of the tables. Keys play a major role when JOINs are used.
There are various types of join which can be used to retrieve data and it depends on the
relationship between tables.
Inner Join.
Inner join return rows when there is at least one match of rows between the tables.
Right Join.
Right join return rows which are common between the tables and all rows of Right hand side
table. Simply, it returns all the rows from the right hand side table even though there are no
matches in the left hand side table.
Left Join.
Left join return rows which are common between the tables and all rows of Left hand side
table. Simply, it returns all the rows from Left hand side table even though there are no
matches in the Right hand side table.
Full Join.
Full join return rows when there are matching rows in any one of the tables. This means, it
returns all the rows from the left hand side table and all the rows from the right hand side
table.
DeNormalization is a technique used to access the data from higher to lower normal forms of
database. It is also process of introducing redundancy into a table by incorporating data from
the related tables.
The normal forms can be divided into 5 forms, and they are explained below -.
This should remove all the duplicate columns from the table. Creation of tables for the related
data and identification of unique columns.
Meeting all requirements of the first normal form. Placing the subsets of data in separate
tables and Creation of relationships between the tables using primary keys.
This should meet all requirements of 2NF. Removing the columns which are not dependent
on primary key constraints.
Meeting all the requirements of third normal form and it should not have multi- valued
dependencies.
A view is a virtual table which consists of a subset of data contained in a table. Views are not
virtually present, and it takes less space to store. View can have data of one or more tables
combined, and it is depending on the relationship.
An index is performance tuning method of allowing faster retrieval of records from the table.
An index creates an entry for each value and it will be faster to retrieve data.
Unique Index.
This indexing does not allow the field to have duplicate values if the column is unique
indexed. Unique index can be applied automatically when primary key is defined.
Clustered Index.
This type of index reorders the physical order of the table and search based on the key values.
Each table can have only one clustered index.
NonClustered Index.
NonClustered Index does not alter the physical order of the table and maintains logical order
of data. Each table can have 999 nonclustered indexes.
A database Cursor is a control which enables traversal over the rows or records in the table.
This can be viewed as a pointer to one row in a set of rows. Cursor is very much useful for
traversing such as retrieval, addition and removal of database records.
Database Relationship is defined as the connection between the tables in a database. There
are various data basing relationships, and they are as follows:.
A DB query is a code written in order to get the information back from the database. Query
can be designed in such a way that it matched with our expectation of the result set. Simply, a
question to the Database.
A subquery is a query within another query. The outer query is called as main query, and
inner query is called subquery. SubQuery is always executed first, and the result of subquery
is passed on to the main query.
A correlated subquery cannot be considered as independent query, but it can refer the column
in a table listed in the FROM the list of the main query.
A Non-Correlated sub query can be considered as independent query and the output of
subquery are substituted in the main query.
A DB trigger is a code or programs that automatically execute with response to some event
on a table or view in a database. Mainly, trigger helps to maintain the integrity of the
database.
Example: When a new student is added to the student database, new records should be
created in the related tables like Exam, Score and Attendance tables.
DELETE command is used to remove rows from the table, and WHERE clause can be used
for conditional set of parameters. Commit and Rollback can be performed after delete
statement.
TRUNCATE removes all rows from the table. Truncate operation cannot be rolled back.
25. What are local and global variables and their differences?
Local variables are the variables which can be used or exist inside the function. They are not
known to the other functions and those variables cannot be referred or used. Variables can be
created whenever that function is called.
Global variables are the variables which can be used or exist throughout the program. Same
variable declared in global cannot be used in functions. Global variables cannot be created
whenever that function is called.
Constraint can be used to specify the limit on the data type of table. Constraint can be
specified while creating or altering the table statement. Sample of constraint are.
NOT NULL.
CHECK.
DEFAULT.
UNIQUE.
PRIMARY KEY.
FOREIGN KEY.
Data Integrity defines the accuracy and consistency of data stored in a database. It can also
define integrity constraints to enforce business rules on the data when it is entered into the
application or database.
Clustered index is used for easy retrieval of data from the database by altering the way that
the records are stored. Database sorts out rows by the column which is set to be clustered
index.
A nonclustered index does not alter the way it was stored but creates a complete separate
object within the table. It point back to the original table rows after searching.
Self-join is set to be query used to compare to itself. This is used to compare values in a
column with other values in the same column in the same table. ALIAS ES can be used for
the same table comparison.
Cross join defines as Cartesian product where number of rows in the first table multiplied by
number of rows in the second table. If suppose, WHERE clause is used in cross join then the
query will work like an INNER JOIN.
User defined functions are the functions written to use that logic whenever required. It is not
necessary to write the same logic several times. Instead, function can be called or executed
whenever needed.
Scalar Functions.
Inline Table valued functions.
Multi statement valued functions.
Scalar returns unit, variant defined the return clause. Other two types return table as a return.
Stored procedure can be used as a modular programming – means create once, store and call
for several times whenever required. This supports faster execution instead of executing
multiple queries. This reduces network traffic and provides better security to the data.
Disadvantage is that it can be executed only in the Database and utilizes more memory in the
database server.
Online Transaction Processing (OLTP) manages transaction based applications which can be
used for data entry, data retrieval and data processing. OLTP makes data management simple
and efficient. Unlike OLAP systems goal of OLTP systems is serving real-time transactions.
SQL clause is defined to limit the result set by providing condition to the query. This usually
filters some rows from the whole set of records.
A stored procedure which calls by itself until it reaches some boundary condition. This
recursive function or procedure helps programmers to use the same set of code any number of
times.
MINUS operator is used to return rows from the first query but not from the second query.
Matching records of first and second query and other rows from the first query will be
displayed as a result set.
ALIAS name can be given to a table or column. This alias name can be referred in WHERE
clause to identify the table or column.
Example-.
Select st.StudentID, Ex.Result from student st, Exam as Ex where st.studentID = Ex.
StudentID
Here, st refers to alias name for student table and Ex refers to alias name for exam table.
TRUNCATE removes all the rows from the table, and it cannot be rolled back. DROP
command removes a table from the database and operation cannot be rolled back.
Aggregate functions are used to evaluate mathematical calculation and return single values.
This can be calculated from the columns in a table. Scalar functions return a single value
based on the input value.
Example -.
45. How can you create an empty table from an existing table?
Here, we are copying student table to another table with the same structure with no rows
copied.
Records can be fetched for both Odd and Even row numbers -.
Select studentId from (Select rowno, studentId from student) where mod(rowno,2)=0
Select studentId from (Select rowno, studentId from student) where mod(rowno,2)=1
49. What is the command used to fetch first 5 characters of the string?
There are many ways to fetch first 5 characters of the string -.
LIKE operator is used for pattern matching, and it can be used as -.
Example -.
The data structure is a way that specifies how to organize and manipulate the data. It also
defines the relationship between them. Some examples of Data Structures are arrays, Linked
List, Stack, Queue, etc. Data Structures are the central part of many computer science
algorithms as they enable the programmers to handle the data in an efficient way
Linear Data Structure: A data structure is called linear if all of its elements are arranged in
the sequential order. In linear data structures, the elements are stored in a non-hierarchical
way where each item has the successors and predecessors except the first and last element.
Non-Linear Data Structure: The Non-linear data structure does not form a sequence i.e.
each item or element is connected with two or more other items in a non-linear arrangement.
The data elements are not arranged in the sequential structure.
Data structures are applied extensively in the following areas of computer science:
o Compiler Design,
o Operating System,
o Database Management System,
o Statistical analysis package,
o Numerical Analysis,
o Graphics,
o Artificial Intelligence,
o Simulation
The main difference between file structure and storage structure is based on memory area that
is being accessed.
Storage structure: It is the representation of the data structure in the computer memory.
File structure: It is the representation of the storage structure in the auxiliary memory.
5) List the data structures which are used in RDBMS, Network Data Modal, and Hierarchical
Data Model.
Stack data structure is used in recursion due to its last in first out nature. Operating system
maintains the stack in order to save the iteration variables at each function call
7) What is a Stack?
Stack is an ordered list in which, insertion and deletion can be performed only at one end that
is called the top. It is a recursive data structure having pointer to its top element. The stack is
sometimes called as Last-In-First-Out (LIFO) list i.e. the element which is inserted first in the
stack will be deleted last from the stack.
8) List the area of applications where stack data structure can be used?
o Expression evaluation
o Backtracking
o Memory Management
o Function calling and return
o Push Operations
o Pop Operations
o Peek Operations
PUSH and POP operations specify how data is stored and retrieved in a stack.
POP: POP specifies data retrieval. It means that data is being deleted from the stack.
12) Write the steps involved in the insertion and deletion of an element in the stack.
Push:
o Increment the variable top so that it can refer to the next memory allocation
o Copy the item to the at the array index value equal to the top
o Repeat step 1 and 2 until stack overflows
Pop:
An expression in which operators follow the operands is known as postfix expression. The
main benefit of this form is that there is no need to group sub-expressions in parentheses or to
consider operator precedence.
AB+CD-*
)15) Which notations are used in Evaluation of Arithmetic Expressions using prefix and
postfix forms?
Arrays are defined as the collection of similar types of data items stored at contiguous
memory locations. It is the simplest data structure in which each data element can be
randomly accessed by using its index number.
It can be done by using an indexed loop such that the counter runs from 0 to the array size
minus one. In this manner, you can reference all the elements in sequence by using the loop
counter as the array subscript.
The multidimensional array can be defined as the array of arrays in which, the data is stored
in tabular form consists of rows and columns. 2D arrays are created to implement a relational
database lookalike data structure. It provides ease of holding the bulk of data at once which
can be passed to any number of functions wherever required.
19) How are the elements of a 2D array are stored in the memory?
There are two techniques by using which, the elements of a 2D array can be stored in the
memory.
o Row-Major Order: In row-major ordering, all the rows of the 2D array are stored
into the memory contiguously. First, the 1st row of the array is stored into the
memory completely, then the 2nd row of the array is stored into the memory
completely and so on till the last row.
o Column-Major Order: In column-major ordering, all the columns of the 2D array
are stored into the memory contiguously. first, the 1st column of the array is stored
into the memory completely, then the 2nd row of the array is stored into the memory
completely and so on till the last column of the array.
20) Calculate the address of a random element present in a 2D array, given base address as
BA.
Row-Major Order: If array is declared as a[m][n] where m is the number of rows while n is
the number of columns, then address of an element a[i][j] of the array stored in row major
order is calculated as,
Address(a[i][j]) = B. A. + (i * n + j) * size
Column-Major Order: If array is declared as a[m][n] where m is the number of rows while
n is the number of columns, then address of an element a[i][j] of the array stored in column
major order is calculated as
Linked List is the collection of randomly stored data objects called nodes. In Linked List,
each node is linked to its adjacent node through a pointer. A node contains two fields, i.e.
Data Field and Link Field.
A linked list is considered both linear and non-linear data structure depending upon the
situation.
o The size of a linked list can be incremented at runtime which is impossible in the case
of the array.
o The List is not required to be contiguously present in the main memory, if the
contiguous space is not available, the nodes can be stored anywhere in the memory
connected through the links.
o The List is dynamically stored in the main memory and grows as per the program
demand while the array is statically stored in the main memory, size of which must be
declared at compile time.
o The number of elements in the linked list are limited to the available memory space
while the number of elements in the array is limited to the size of an array.
24) Write the syntax in C to create a node in the singly linked list.
1. struct node
2. {
3. int data;
4. struct node *next;
5. };
6. struct node *head, *ptr;
7. ptr = (struct node *)malloc(sizeof(struct node));
25) If you are using C language to implement the heterogeneous linked list, what pointer type
should be used?
The heterogeneous linked list contains different data types, so it is not possible to use
ordinary pointers for this. For this purpose, you have to use a generic pointer type like void
pointer because the void pointer is capable of storing a pointer to any type.
The doubly linked list is a complex type of linked list in which a node contains a pointer to
the previous as well as the next node in the sequence. In a doubly linked list, a node consists
of three parts:
o node data
o pointer to the next node in sequence (next pointer)
o pointer to the previous node (previous pointer).
27) Write the C program to insert a node in circular singly list at the beginning.
1. #include<stdio.h>
2. #include<stdlib.h>
3. void beg_insert(int);
4. struct node
5. {
6. int data;
7. struct node *next;
8. };
9. struct node *head;
10. void main ()
11. {
12. int choice,item;
13. do
14. {
15. printf("\nEnter the item which you want to insert?\n");
16. scanf("%d",&item);
17. beg_insert(item);
18. printf("\nPress 0 to insert more ?\n");
19. scanf("%d",&choice);
20. }while(choice == 0);
21. }
22. void beg_insert(int item)
23. {
24.
25. struct node *ptr = (struct node *)malloc(sizeof(struct node));
26. struct node *temp;
27. if(ptr == NULL)
28. {
29. printf("\nOVERFLOW");
30. }
31. else
32. {
33. ptr -> data = item;
34. if(head == NULL)
35. {
36. head = ptr;
37. ptr -> next = head;
38. }
39. else
40. {
41. temp = head;
42. while(temp->next != head)
43. temp = temp->next;
44. ptr->next = head;
45. temp -> next = ptr;
46. head = ptr;
47. }
48. printf("\nNode Inserted\n");
49. }
50.
51. }
52.
A queue can be defined as an ordered list which enables insert operations to be performed at
one end called REAR and delete operations to be performed at another end called FRONT.
o Queues are widely used as waiting lists for a single shared resource like a printer,
disk, CPU.
o Queues are used in the asynchronous transfer of data (where data is not being
transferred at the same rate between two processes) for eg. pipes, file IO, sockets.
o Queues are used as buffers in most of the applications like MP3 media player, CD
player, etc.
o Queues are used to maintain the playlist in media players to add and remove the songs
from the play-list.
o Queues are used in operating systems for handling interrupts.
o Memory Wastage: The space of the array, which is used to store queue elements, can
never be reused to store the elements of that queue because the elements can only be
inserted at front end and the value of front might be so high so that, all the space
before that, can never be filled.
o Array Size: There might be situations in which, we may need to extend the queue to
insert more elements if we use an array to implement queue, It will almost be
impossible to extend the array size, therefore deciding the correct array size is always
a problem in array implementation of queue.
31) What are the scenarios in which an element can be inserted into the circular queue?
o If (rear + 1)%maxsize = front, the queue is full. In that case, overflow occurs and
therefore, insertion can not be performed in the queue.
o If rear != max - 1, the rear will be incremented to the mod(maxsize) and the new value
will be inserted at the rear end of the queue.
o If front != 0 and rear = max - 1, it means that queue is not full therefore, set the value
of rear to 0 and insert the new element there.
32) What is a dequeue?
Dequeue (also known as double-ended queue) can be defined as an ordered set of elements in
which the insertion and deletion can be performed at both the ends, i.e. front and rear.
33) What is the minimum number of queues that can be used to implement a priority queue?
Two queues are needed. One queue is used to store the data elements, and another is used for
storing priorities.
The Tree is a recursive data structure containing the set of one or more data nodes where one
node is designated as the root of the tree while the remaining nodes are called as the children
of the root. The nodes other than the root node are partitioned into the nonempty sets where
each one of them is to be called sub-tree.
o General Tree
o Forests
o Binary Tree
o Binary Search Tree
o Expression Tree
o Tournament Tree
A binary Tree is a special type of generic tree in which, each node can have at most two
children. Binary tree is generally partitioned into three disjoint subsets, i.e. the root of the
node, left sub-tree and Right binary sub-tree.
39) Which data structure suits the most in the tree construction?
40) Which data structure suits the most in the tree construction?
41) Write the recursive C function to count the number of nodes present in a binary tree.
1. int count (struct node* t)
2. {
3. if(t)
4. {
5. int l, r;
6. l = count(t->left);
7. r=count(t->right);
8. return (1+l+r);
9. }
10. else
11. {
12. return 0;
13. }
14. }
1. int countHeight(struct node* t)
2. {
3. int l,r;
4. if(!t)
5. return 0;
6. if((!(t->left)) && (!(t->right)))
7. return 0;
8. l=countHeight(t->left);
9. r=countHeight(t->right);
10. return (1+((l>r)?l:r));
11. }
43) How can AVL Tree be useful in all the operations as compared to Binary search tree?
AVL tree controls the height of the binary search tree by not letting it be skewed. The time
taken for all operations in a binary search tree of height h is O(h). However, it can be
extended to O(n) if the BST becomes skewed (i.e. worst case). By limiting this height to log
n, AVL tree imposes an upper bound on each operation to be O(log n) where n is the number
of nodes.
A B tree of order m contains all the properties of an M way tree. In addition, it contains the
following properties.
S B Tree B+ Tree
N
1 Search keys cannot repeatedly be stored. Redundant search keys can be present.
2 Data can be stored in leaf nodes as well Data can only be stored on the leaf
as internal nodes nodes.
5 Leaf nodes cannot be linked together. Leaf nodes are linked together to make
the search operations more efficient.
A graph G can be defined as an ordered set G(V, E) where V(G) represents the set of vertices
and E(G) represents the set of edges which are used to connect these vertices. A graph can be
seen as a cyclic tree, where the vertices (Nodes) maintain any complex relationship among
them instead of having parent-child relations.
o Path: A Path is the sequence of adjacent vertices connected by the edges with no
restrictions.
o Cycle: A Cycle can be defined as the closed path where the initial vertex is identical
to the end vertex. Any vertex in the path can not be visited twice
o Circuit: A Circuit can be defined as the closed path where the intial vertex is
identical to the end vertex. Any vertex may be repeated.
49) Mention the data structures which are used in graph implementation.
o Graphs are used in circuit networks where points of connection are drawn as vertices
and component wires become the edges of the graph.
o Graphs are used in transport networks where stations are drawn as vertices and routes
become the edges of the graph.
o Graphs are used in maps that draw cities/states/regions as vertices and adjacency
relations as edges.
o Graphs are used in program flow analysis where procedures or modules are treated as
vertices and calls to these procedures are drawn as edges of the graph.
Binary Search algorithm is used to search an already sorted list. The algorithm follows divide
and conqer approach
Example:
52) What are the advantages of Binary search over linear search?
There are relatively less number of comparisons in binary search than that in linear search. In
average case, linear search takes O(n) time to search a list of n elements while Binary search
takes O(log n) time to search a list of n elements.
o Sparse matrix,
o Index generation.
o It is designed to make sure that a computer system performs well by managing its
computational activities.
o It provides an environment for the development and execution of programs.
4) What is a socket?
A socket is used to make connection between two applications. Endpoints of the connection
are called socket.
Real-time system is used in the case when rigid-time requirements have been placed on the
operation of a processor. It contains a well defined and fixed time constraints.
6) What is kernel?
Kernel is the core and most important part of a computer operating system which provides
basic services for all parts of the OS.
A monolithic kernel is a kernel which includes all operating system code is in single
executable image.
8) What do you mean by a process?
o New Process
o Running Process
o Waiting Process
o Ready Process
o Terminated Process
10) What is the difference between micro kernel and macro kernel?
Micro kernel: micro kernel is the kernel which runs minimal performance affecting services
for operating system. In micro kernel operating system all other operations are performed by
processor.
It is a very useful memory saving technique that is used for multi-programmed time sharing
systems. It provides functionality that multiple users can share a single copy of program
during the same period.
Paging is used to solve the external fragmentation problem in operating system. This
technique ensures that the data you need is available as quickly as possible.
Demand paging specifies that if an area of memory is not currently being used, it is swapped
to disk to make room for an application's need.
As many as processors are increased, you will get the considerable increment in throughput.
It is cost effective also because they can share resources. So, the overall reliability increases.
Virtual memory is a very useful memory management technique which enables processes to
execute outside of memory. This technique is especially used when an executing program
cannot fit in the physical memory.
Thrashing is a phenomenon in virtual memory scheme when the processor spends most of its
time in swapping pages, rather than executing instructions.
18) What are the four necessary and sufficient conditions behind the deadlock?
1) Mutual Exclusion Condition: It specifies that the resources involved are non-sharable.
2) Hold and Wait Condition: It specifies that there must be a process that is holding a
resource already allocated to it while waiting for additional resource that are currently being
held by other processes.
3) No-Preemptive Condition: Resources cannot be taken away while they are being used by
processes.
4) Circular Wait Condition: It is an explanation of the second condition. It specifies that the
processes in the system form a circular list or a chain where each process in the chain is
waiting for a resource held by next process in the chain.
A thread is a basic unit of CPU utilization. It consists of a thread ID, program counter,
register set and a stack.
FCFS stands for First Come, First Served. It is a type of scheduling algorithm. In this scheme,
if a process requests the CPU first, it is allocated to the CPU first. Its implementation is
managed by a FIFO queue.
SMP stands for Symmetric MultiProcessing. It is the most common type of multiple
processor system. In SMP, each processor runs an identical copy of the operating system, and
these copies communicate with one another when required.
RAID stands for Redundant Array of Independent Disks. It is used to store the same data
redundantly to improve the overall performance.
Deadlock is a specific situation or condition where two processes are waiting for each other
to complete so that they can start. But this situation causes hang for both of them.
o Mutual Exclusion: At least one resource must be held in a non-sharable mode. If any
other process requests this resource, then that process must wait for the resource to be
released.
o Hold and Wait: A process must be simultaneously holding at least one resource and
waiting for at least one resource that is currently being held by some other process.
o No preemption: Once a process is holding a resource ( i.e. once its request has been
granted ), then that resource cannot be taken away from that process until the process
voluntarily releases it.
o Circular Wait: A set of processes { P0, P1, P2, . . ., PN } must exist such that every
P[ i ] is waiting for P[ ( i + 1 ) % ( N + 1 ) ].
Note: This condition implies the hold-and-wait condition, but it is easier to deal with the
conditions if the four are considered separately.
26) What is the difference between logical address space and physical address space?
Logical address space specifies the address that is generated by CPU. On the other hand
physical address space specifies the address that is seen by the memory unit.
o Internal fragmentation: It is occurred when we deal with the systems that have fixed
size allocation units.
o External fragmentation: It is occurred when we deal with systems that have
variable-size allocation units.
30) What is the difference between internal commands and external commands?
Internal commands are the built-in part of the operating system while external commands are
the separate file programs that are stored in a separate folder or directory.
Semaphore is a protected variable or abstract data type that is used to lock the resource being
used. The value of the semaphore indicates the status of a common resource.
o Binary semaphores
o Counting semaphores
Binary semaphore takes only 0 and 1 as value and used to implement mutual exclusion and
synchronize concurrent processes.
Starvation is Resource management problem. In this problem, a waiting process does not get
the resources it needs for a long time because the resources are being allocated to other
processes.
37) What is the difference between logical and physical address space?
Logical address specifies the address which is generated by the CPU whereas physical
address specifies to the address which is seen by the memory unit.
After fragmentation
Overlays makes a process to be larger than the amount of memory allocated to it. It ensures
that only important instructions and data at any given time are kept in memory.
39) When does trashing occur?
Thrashing specifies an instance of high paging activity. This happens when it is spending
more time paging instead of executing.
Type Description
All the devices share a common
Bus Topology
communication line
All nodes are connected to a central hub
Star Topology
device
Each node connects to exactly two other
Ring Topology
nodes
Mesh Topology Each node is connected to one or more nodes
Similar to star topology and inherits the bus
Tree Topology (Hierarchical Topology)
topology
Daisy Chain Topology All nodes are connected linearly
Nodes are connected in more than one
Hybrid Topology
topology styles
Connects two hosts such as computers,
Point-to-Point Topology
servers, etc
Q6. Explain what is LAN?
A LAN or Local Area Network the network between devices that are located within a small
physical location. It can be either wireless or wired. One LAN differs from another based on
the following factors:
Routers can either be stand-alone devices or virtual. Stand-alone routers are traditional
devices where as virtual routers are actually softwares that act like physical ones.
1. Physical Layer
2. Data Link Layer
3. Network Layer
4. Transport Layer
5. Session Layer
6. Presentation Layer
7. Application Layer
Q10. Give a brief about each layer in the OSI Model.
Layer Name Protocol Description
Transfers raw bits of data over
Physical Layer Symbol
a physical link
Reliable transmission of data
frames between nodes
Data Link Layer Frame
connected by the physical
layer
Structures and manages a
network with multiple nodes
Network Layer Packet
including addressing, routing
and traffic control
Reliable Transmission of data
Transport Layer Segment, Datagram packets between the different
points of a network
Manages the communication
Session Layer Data
sessions
Transmission of data between
Presentation Layer Data the service device and the
application
Specifies the shared
Application Layer Data communication protocols and
the interface methods
To learn about Network Programming in Java and Python in detail refer to the following
blogs:
So in case you are asked to use anonymous ftp, make sure you add “anonymous” in place of
your user id. Anonymous FTPs are very effective while distributing large files to a lot of
people, without having to give huge numbers of usernames and password combinations.
This Subnet mask is basically a 32-bit number and it masks the IP address and then divides
the IP address into two parts i.e the network address and the host address. Subnet Masks are
created by setting all the network bits to “1” and all the host bits to “0”s. There are two
network addresses that cannot be assigned to any host on the network i.e The “0” and “255”
which are assigned to network and to the broadcast address, and this is why they cannot be
assigned to any host.
1. Process(Application Layer)
2. Host-to-Host(Transport Layer)
3. Internet Layer (Network Layer)
4. Network Access(Combination of Physical and Data Link Layer)
Q15. What is the difference between the OSI Model and TCP/ IP Model?
A UTP cable is a 100 ohms cable made up of copper. It consists of 2-1800 unshielded twisted
pairs that are surrounded by a non-metallic case. These twists provide immunity to electrical
noise and EMI.
The maximum length allowed for a UTP cable is 100m. This includes 90 m of solid cabling
and 10m of standard patch cable.
HTTP or HyperText Transfer Protocol allows communication over the Internet. This protocol
basically defines how messages are to be transmitted and formatted over the world wide web.
HTTP is a TCP/ IP protocol and it uses the port number 80.
It is connection-less
Does not depend on the type of connecting media
Stateless
All devices connected to the internet have unique IP addresses which are used to locate them
on the network. The process involves conversion on hostnames into IP addresses. For
example, in case the user wants to load some web page (xyz.com), this hostname is converted
into an IP address that can be understood by the computer in order to load that web page.
Q40. In a network that contains two servers and twenty workstations, where is the best place
to install an Anti-virus program?
The best solution is to install anti-virus on all the computers in the network. This will protect
each device from the other in case some malicious user tries to insert a virus into the servers
or legitimate users.
Q42.What is SLIP?
SLIP stands for Serial Line Internet Protocol which allows a user to access the internet using
the modem.
Name Description
Syntax Refers to the structure and format of data
Semantics Refers to the meaning of each portion of bits
Refers to when data should be sent and
Timing
received
All projects are broadly divided into two types of applications 2 tier and 3 tier
architecture. Basically high level we can say that 2-tier architecture is Client server
application and 3-tier architecture is Web based application. Below I am concentrating on the
difference between Two-Tier and Three-Tier Architecture, what all advantages,
disadvantages and practical examples.
Two-Tier Architecture:
The two-tier is based on Client Server architecture. The two-tier architecture is like client
server application. The direct communication takes place between client and server. There is
no intermediate between client and server. Because of tight coupling a 2 tiered application
will run faster.
Two-
Tier Architecture
The above figure shows the architecture of two-tier. Here the direct communication between
client and server, there is no intermediate between client and server.
Let’s take a look of real life example of Railway Reservation two-tier architecture:
Let’s consider that first Person is making Railway Reservation for Mumbai to Delhi by
Mumbai Express at Counter No. 1 and at same time second Person is also try to make
Railway reservation of Mumbai to Delhi from Counter No. 2
If staff from Counter No. 1 is searching for availability into system & at the same staff from
Counter No. 2 is also looking for availability of ticket for same day then in this case there is
might be good change of confusion and chaos occurs. There might be chance of lock the
Railway reservation that reserves the first.
But reservations can be making anywhere from the India, then how it is handled?
So here if there is difference of micro seconds for making reservation by staff from Counter
No. 1 & 2 then second request is added into queue. So in this case the Staff is entering data to
Client Application and reservation request is sent to the database. The database sends back
the information/data to the client.
In this application the Staff user is an end user who is using Railway reservation application
software. He gives inputs to the application software and it sends requests to Server. So here
both Database and Server are incorporated with each other, so this technology is called as
“Client-Server Technology“.
The Two-tier architecture is divided into two parts:
Advantages:
1. Easy to maintain and modification is bit easy
2. Communication is faster
Disadvantages:
1. In two tier architecture application performance will be degrade upon increasing the
users.
2. Cost-ineffective
Three-Tier Architecture:
2) Business layer:
In this layer all business logic written like validation of data, calculations, data insertion etc.
This acts as a interface between Client layer and Data Access Layer. This layer is also called
the intermediary layer helps to make communication faster between client and data layer.
3) Data layer:
In this layer actual database is comes in the picture. Data Access Layer contains methods to
connect with database and to perform insert, update, delete, get data from database based on
our input data.
Three-tier Architecture
Advantages
1. Increase Complexity/Effort
C++ is a low level programming language that adds object-oriented features to its
base language C whereas C# is a high level language.
C++ compiles down to machine code whereas C# 'compiles' down to CLR (Common
Language Runtime), which is interpreted by JIT in ASP.NET.
C++ is an object-oriented language while C# is considered a component-oriented
programming language.
In C++ you need to manage memory manually whereas C# runs in a virtual machine,
which performs memory management automatically.
In C++ development should follow any specific architecture and must be portable
whereas C# development should be simple, modem, general-purpose, object-oriented
programming language.