Sie sind auf Seite 1von 32

INTERVIEW QUESTION

1) Swap two variables without using third variable.


a=b+a;
b=a-b;
a=a-b;
2) What is difference between pass by value and pass by reference?

In c we can pass the parameters in a function in two different ways.

(a)Pass by value: In this approach we pass copy of actual variables in function as a


parameter. Hence any modification on parameters inside the function will not reflect in the
actual variable. For example:

#include<stdio.h>
int main(){
int a=5,b=10;
swap(a,b);
printf("%d %d",a,b);
return 0;
}
void swap(int a,int b){
int temp;
temp =a;
a=b;
b=temp;
}
Output: 5 10

(b)Pass by reference: In this approach we pass memory address actual variables in function
as a parameter. Hence any modification on parameters inside the function will reflect in the
actual variable. For example:

#incude<stdio.h>
int main(){
int a=5,b=10;
swap(&a,&b);
printf("%d %d",a,b);
return 0;
}
void swap(int *a,int *b){
int *temp;
*temp =*a;
*a=*b;
*b=*temp;
}

Output: 10 5
3) What is and why array in c?
Explanation:
An array is derived data type in c programming language which can store similar type of data
in continuous memory location. Data may be primitive type (int, char, float, double),
address of union, structure, pointer, function or another array.
Example of array declaration:

int arr[5];
char arr[5];
float arr[5];
long double arr[5];
char * arr[5];
int (arr[])();
double ** arr[5];

Array is useful when:

(a) We have to store large number of data of similar type. If we have large number of similar
kind of variable then it is very difficult to remember name of all variables and write the
program. For example:

//PROCESS ONE
int main(){
int ax=1;
int b=2;
int cg=5;
int dff=7;
int am=8;
int raja=0;
int rani=11;
int xxx=5;
int yyy=90;
int p;
int q;
int r;
int avg;
avg=(ax+b+cg+dff+am+raja+rani+xxx+yyy+p+q+r)/12;
printf("%d",avg);
return 0;
}
If we will use array then above program can be written as:

//PROCESS TWO
int main(){
int arr[]={1,2,5,7,8,0,11,5,50};
int i,avg;
for(int i=0;i<12;i++){
avg=avg+arr[i];
}
printf("%d",avg/12);
return 0;
}

Question: Write a C program to find out average of 200 integer number using process one
and two.

(b) We want to store large number of data in continuous memory location. Array always
stores data in continuous memory location.

What will be output when you will execute the following program?

int main(){
int arr[]={0,10,20,30,40};
char *ptr=arr;
arr=arr+2;
printf("%d",*arr);
return 0;
}

Advantage of using array:

1. An array provides singe name .So it easy to remember the name of all element of an array.
2. Array name gives base address of an array .So with the help increment operator we can
visit one by one all the element of an array.
4) How to add two numbers without using the plus operator in c

#include<stdio.h>

int main(){

int a,b;
int sum;

printf("Enter any two integers: ");


scanf("%d%d",&a,&b);

//sum = a - (-b);
sum = a - ~b -1;

printf("Sum of two integers: %d",sum);


return 0;
}

Sample output:

Enter any two integers: 5 10

Sum of two integers: 15

Algorithm:

In c ~ is 1's complement operator. This is equivalent to:


~a = -b + 1
So, a - ~b -1
= a-(-b + 1) + 1
=a+b1+1
=a+b
5) Bubble sorting algorithm
for(i=s-2;i>=0;i--){
for(j=0;j<=i;j++){
if(a[j]>a[j+1]){
temp=a[j];
a[j]=a[j+1];
a[j+1]=temp;
}
}
}

printf("After sorting: ");


for(i=0;i<s;i++)
printf(" %d",a[i]);

return 0;
}
6) Fibonacci series:
printf("Enter the number range:");
scanf("%d",&r);

printf("FIBONACCI SERIES: ");


printf("%ld %ld",i,j); //printing firts two values.

for(k=2;k<r;k++){
f=i+j;
i=j;
j=f;
printf(" %ld",j);
}

return 0;
}

Sample output:
Enter the number range: 15
FIBONACCI SERIES: 0 1 1 2 3 5 8 13 21 34 55 89 144 233 377

Output:
Enter total numbers of elements: 5
Enter 5 elements: 6 2 0 11 9
After sorting: 0 2 6 9 11

7) differences between structures and arrays

The following are the differences between structures and arrays:

- Array elements are homogeneous. Structure elements are of different data type.
- Array allocates static memory and uses index / subscript for accessing elements of the
array. Structures allocate dynamic memory and uses (.) operator for accessing the member
of a structure.
- Array is a pointer to the first element of it. Structure is not a pointer
- Array element access takes less time in comparison with structures.

8) Explain the meaning of "Segmentation violation".

Segmentation violation usually occurs at the time of a programs attempt for accessing
memory location, which is not allowed to access. The following code should create
segmentation violation.

main() {
char *hello = Hello World;
*hello = h;
}

At the time of compiling the program, the string hello world is placed in the binary mark of
the program which is read-only marked. When loading, the compiler places the string along
with other constants in the read-only segment of the memory. While executing a variable
*hello is set to point the character h , is attempted to write the character h into the
memory, which cause the segmentation violation. And, compiler does not check for
assigning read only locations at compile time.
9) Floyds Triangle
#include<stdio.h>

int main(){

int i,j,r,k=1;

printf("Enter the range: ");


scanf("%d",&r);

printf("FLOYD'S TRIANGLE\n\n");
for(i=1;i<=r;i++){
for(j=1;j<=i;j++,k++)
printf(" %d",k);
printf("\n");
}

return 0;
}

Sample output:
Enter the range: 10
FLOYD'S TRIANGLE

1
23
456
7 8 9 10
11 12 13 14 15
16 17 18 19 20 21
22 23 24 25 26 27 28
29 30 31 32 33 34 35 36
37 38 39 40 41 42 43 44 45
46 47 48 49 50 51 52 53 54 55

10) Pascals Triangle


#include<stdio.h>

long fact(int);
int main(){
int line,i,j;

printf("Enter the no. of lines: ");


scanf("%d",&line);
for(i=0;i<line;i++){
for(j=0;j<line-i-1;j++)
printf(" ");

for(j=0;j<=i;j++)
printf("%ld ",fact(i)/(fact(j)*fact(i-j)));
printf("\n");
}
return 0;
}

long fact(int num){


long f=1;
int i=1;
while(i<=num){
f=f*i;
i++;
}
return f;
}

Sample output:

Enter the no. of lines: 8


1
11
121
1331
14641
1 5 10 10 5 1
1 6 15 20 15 6 1
1 7 21 35 35 21 7 1

11) What are the different storage class specifiers in C?

There are 4 storage class specifiers in C, out of which auto and static act as storage classes as
well. So, the storage class specifiers are:

Auto
Register
Static
Extern

12) What are static functions? What is their use in C?


In the C programming language, all functions are global by default. Therefore, to make a
function static, the static keyword is used before the function. Unlike the global functions,
access to static functions in C is restricted to the file where they are declared.

The use of static functions in C are:

to make a function static


to restrict access to functions
to reuse the same function name in other file

13) What is the size of void pointer in C?

Whether its char pointer, function pointer, null pointer, double pointer, void pointer or any
other, the size of any type of pointer in C is of two byte. In C, the size of any pointer type is
independent of data type.

14) What are the differences between Structure and Unions?

1. Every member in structure has its own memory, whereas the members in a union
share the same member space.
2. Initialization of all the member at the same time is possible in structures but not in
unions.
3. For the same type of member, a structure requires more space than a union.
4. Different interpretations of the same memory space is possible in union but not in
structures.

15) Differences Between C and C++ :

C C++
1. C++ is non Procedural i.e Object
1. C is Procedural Language.
oriented Language.
2. The concept of virtual Functions are
2. No virtual Functions are present in C
used in C++.
3. The concept of polymorphism is used
in C++.
3. In C, Polymorphism is not possible.
Polymorphism is the most Important
Feature of OOPS.
4. Operator overloading is one of the
4. Operator overloading is not possible in C.
greatest Feature of C++.
5. Bottom up approach adopted in
5. Top down approach is used in Program Design.
Program Design.
6. No namespace Feature is present in C 6. Namespace Feature is present in C++
Language. for avoiding Name collision.
7. Multiple Declaration of global variables are 7. Multiple Declaration of global
allowed. varioables are not allowed.
8. In C 8. In C++
scanf() Function used for Input. Cin>> Function used for Input.

printf() Function used for output. Cout<< Function used for output.
9. Mapping between Data and Function is difficult 9. Mapping between Data and Function
and complicated. can be used using "Objects"
10. In C, we can call main() Function through other 10. In C++, we cannot call main() Function
Functions through other functions.
11. C++ allows the declaration of variable
11. C requires all the variables to be defined at the
anywhere in the scope i.e at time of its
starting of a scope.
First use.
12. No inheritance is possible in C. 12. Inheritance is possible in C++
13. In C, malloc() and calloc() Functions are used 13.In C++, new and delete operators are
for Memory Allocation and free() function for used for Memory Allocating and
memory Deallocating. Deallocating.
14. It support both built-in and user
14. It supports built-in and primitive data types.
define data types.
15. In C++, Exception Handling is done
15. In C, Exception Handling is not present.
with Try and Catch block.

16) What is the difference between calloc() and malloc() ?

calloc(...) allocates a block of memory for an array of elements of a certain size. By default
the block is initialized to 0. The total number of memory allocated will be
(number_of_elements * size).

malloc(...) takes in only a single argument which is the memory required in bytes. malloc(...)
allocated bytes of memory and not blocks of memory like calloc(...).

malloc(...) allocates memory blocks and returns a void pointer to the allocated space, or
NULL if there is insufficient memory available.

calloc(...) allocates an array in memory with elements initialized to 0 and returns a pointer to
the allocated space. calloc(...) calls malloc(...) in order to use the C++ _set_new_mode
function to set the new handler mode.

17) What is the difference between strings and character arrays?

A major difference is: string will have static storage duration, whereas as a character array
will not, unless it is explicity specified by using the static keyword.

Actually, a string is a character array with following properties:


* the multibyte character sequence, to which we generally call string, is used to initialize an
array of static storage duration. The size of this array is just sufficient to contain these
characters plus the terminating NUL character.
* it not specified what happens if this array, i.e., string, is modified.
* Two strings of same value[1] may share same memory area.

18) What is a pointer?

Pointer is a variable that contains address of another variable in the memory. Pointers are
quite useful in creation of linked data structures (such as linked lst, trees graphs), managing
object allocated memory dynamically, optimize the program to execute faster and use less
memory

19) What are macros? What are its advantages and disadvantages?

Macro is a Pre-processor.Major advantage of using the macro is to increase the speed of the
execution of the program.
Major disadvantage of the macros are:
(i) No type checking is performed in macro. This may cause error.
(ii) A macro call may cause unexpected results.

20) Differentiate between a for loop and a while loop? What are it uses?

For executing a set of statements fixed number of times we use for loop while when the
number of
iterations to be performed is not known in advance we use while loop

21) What are the uses of a pointer?

(i)It is used to access array elements


(ii)It is used for dynamic memory allocation.
(iii)It is used in Call by reference
(iv)It is used in data structures like trees, graph, linked list etc

22) Difference between formal argument and actual argument?


Formal arguments are the arguments available in the function definition. They are
preceded by their own data type. Actual arguments are available in the function call.
These arguments are given as constants or variables or expressions to pass the values to
the function.
23) What are different methods of collision resolution in hashing.

A collision occurs whenever a key is mapped to an address that is already occupied. Collision
Resolution technique provides an alternate place in hash table where this key can be placed.
Collision Resolution technique can be classified as:

1) Open Addressing (Closed Hashing)

a) Linear Probing
b) Quadratic Probing
c) Double Hashing

2) Separate Chaining (Open Hashing)

24) Describe binary tree and its property.

In a binary tree a node can have maximum two children, or in other words we can say a
node can have 0,1, or 2 children.

Properties of binary tree.

1) The maximum number of nodes on any level i is 2i where i>=0.

2) The maximum number of nodes possible in a binary tree of height h is 2 h-1.

3) The minimum number of nodes possible in a binary tree of height h is equal to h.

4) If a binary tree contains n nodes then its maximum possible height is n and minimum
height possible is log2 (n+1).

5) If n is the total no of nodes and e is the total no of edges then e=n-1.The tree must be
non-empty binary tree.

6) If n0 is the number of nodes with no child and n2 is the number of nodes with 2 children,
then n0=n2+1.

25) What are different application of stack.

Some of the applications of stack are as follows:

- Function calls.
- Reversal of a string.
- Checking validity of an expression containing nested parenthesis.
- Conversion of infix expression to postfix.
26) What is Data Structure?

- Data structure is a group of data elements grouped together under one name.
- These data elements are called members. They can have different types and different
lengths.
- Some of them store the data of same type while others store different types of data.

27) What is a queue ?

- A Queue refers to a sequential organization of data.


- It is a FIFO type data structure in which an element is always inserted at the last position
and any element is always removed from the first position

28) What is a postfix expression?

- It is an expression in which each operator follows its operands.


- Here, there is no need to group sub-expressions in parentheses or to consider operator
precedence

29) Quick sort employs the divide and conquer concept by dividing the list of elements into
two sub elements

The process is as follows:

1. Select an element, pivot, from the list.


2. Rearrange the elements in the list, so that all elements those are less than the pivot are
arranged before the pivot and all elements those are greater than the pivot are arranged
after the pivot. Now the pivot is in its position.
3. Sort the both sub lists sub list of the elements which are less than the pivot and the list
of elements which are more than the pivot recursively.

Merge Sort: A comparison based sorting algorithm. The input order is preserved in the
sorted output. Run time is T(n log n).

Merge Sort algorithm is as follows:

1. The length of the list is 0 or 1, and then it is considered as sorted.


2. Other wise, divide the unsorted list into 2 lists each about half the size.
3. Sort each sub list recursively. Implement the step 2 until the two sub lists
are sorted.
4. As a final step, combine (merge) both the lists back into one sorted list.
30)Bubble Sort: The simplest sorting algorithm. It involves the sorting the list in a repetitive
fashion. It compares two adjacent elements in the list, and swaps them if they are not in the
designated order. It continues until there are no swaps needed. This is the signal for the list
that is sorted. It is also called as comparison sort as it uses comparisons.

Quick Sort: The best sorting algorithm which implements the divide and conquer concept.
It first divides the list into two parts by picking an element a pivot. It then arranges the
elements those are smaller than pivot into one sub list and the elements those are greater
than pivot into one sub list by keeping the pivot in its original place.

31) What is the difference between a stack and a Queue?

Stack Represents the collection of elements in Last In First Out order.


Operations includes testing null stack, finding the top element in the stack, removal of top
most element and adding elements on the top of the stack.

Queue - Represents the collection of elements in First In First Out order.


Operations include testing null queue, finding the next element, removal of elements and
inserting the elements from the queue.
Insertion of elements is at the end of the queue
Deletion of elements is from the beginning of the queue.

32) Explain in brief a linked list.

A linked list a linear arrangement of data. It allows the programmer to insert data anywhere
within the list. The pointer of the list always points to the first node and can be moved
programmatically to insert, delete or update any data. Each node in the list contains a data
value and the address or a reference to the adjoining node. A linked list is a dynamic data
structure. It consists of a sequence of data elements and a reference to the next record in
the sequence. Stacks, queues, hash tables, linear equations, prefix and post fix operations.
The order of linked items is different that of arrays. The insertion or deletion operations are
constant in number.

33) Define a linear and non linear data structure.

Linear data structure: A linear data structure traverses the data elements sequentially, in
which only one data element can directly be reached. Ex: Arrays, Linked Lists

Non-Linear data structure: Every data item is attached to several other data items in a way
that is specific for reflecting relationships. The data items are not arranged in a sequential
structure. Ex: Trees, Graphs

34) Which data structure is applied when dealing with a recursive function?
Recursion, which is basically a function that calls itself based on a terminating condition,
makes use of the stack. Using LIFO, a call to a recursive function saves the return address so
that it knows how to return to the calling function after the call terminates

35) What are multidimensional arrays?

Multidimensional arrays make use of multiple indexes to store data. It is useful when storing
data that cannot be represented using a single dimensional indexing, such as data
representation in a board game, tables with data stored in more than one column.

36) What is Data abstraction?

Data abstraction is a powerful tool for breaking down complex data problems into
manageable chunks. This is applied by initially specifying the data objects involved and the
operations to be performed on these data objects without being overly concerned with how
the data objects will be represented and stored in memory.

37) What is an AVL tree?

An AVL tree is a type of binary search tree that is always in a state of partially balanced. The
balance is measured as a difference between the heights of the subtrees from the root. This
self-balancing tree was known to be the first data structure to be designed as such.

38) What are the advantages of inheritance?

It permits code reusability. Reusability saves time in program development. It encourages


the reuse of proven and debugged high-quality software, thus reducing problem after a
system becomes functional.

39) How do you write a function that can reverse a linked-list?

void reverselist(void)
{
if(head==0)
return;
if(head->next==0)
return;
if(head->next==tail)
{
head->next = 0;
tail->next = head;
}
else
{
node* pre = head;
node* cur = head->next;
node* curnext = cur->next;
head->next = 0;
cur-> next = head;

for(; curnext!=0; )
{
cur->next = pre;
pre = cur;
cur = curnext;
curnext = curnext->next;
}

curnext->next = cur;
}
}

40) What do you mean by inline function?

The idea behind inline functions is to insert the code of a called function at the point where
the function is called. If done carefully, this can improve the application's performance in
exchange for increased compile time and possibly (but not always) an increase in the size of
the generated binary executables

41) What is public, protected, private?

Public, protected and private are three access specifiers in C++.


Public data members and member functions are accessible outside the class.
Protected data members and member functions are only available to derived classes.
Private data members and member functions cant be accessed outside the class.
However there is an exception can be using friend classes

42) What is polymorphism?


Polymorphism is the idea that a base class can be inherited by several classes. A base class
pointer can point to its child class and a base class array can store different child class
objects.

43) What are the advantages of inheritance?


It permits code reusability.
Reusability saves time in program development.
It encourages the reuse of proven and debugged high-quality software, thus reducing
problem after a system becomes functional.

44) Define a constructor - What it is and how it might be called (2 methods).

Answer1
constructor is a member function of the class, with the name of the function being the same
as the class name. It also specifies how the object should be initialized.

Ways of calling constructor:


1) Implicitly: automatically by complier when an object is created.
2) Calling the constructors explicitly is possible, but it makes the code unverifiable.

Answer2
class Point2D{
int x; int y;
public Point2D() : x(0) , y(0) {} //default (no argument) constructor
};

main(){

Point2D MyPoint; // Implicit Constructor call. In order to allocate memory on stack, the
default constructor is implicitly called.

Point2D * pPoint = new Point2D(); // Explicit Constructor call. In order to allocate memory
on HEAP we call the default constructor

45) What are the elements of OBJECT ORIENTED PROGRAMMING?

The main concepts of object oriented programming are :


Data Abstraction
Encapsulation
Inheritance
Polymorphism
46) What is an object?

An object is an instance of a class. It can be uniquely identified by its name and it defines a
state, which is represented by the values of its attributes at a particular point in time.

47) What is class?

A class is a collection of objects. A class may be defined as a group of objects with same
operations and attributes. The class is a key word in C++ programming. The user deals with
classes instead of dealing with various individual objects.

48) What are the advantages of OOPs?

Object Oriented Programming has the following advantages over conventional


approaches :
OOP provides a clear modular structure for programs which makes it good for
defining abstract data types where implementation details are hidden and the unit
has a clearly defined interface.
OOP makes it easy to maintain and modify existing code as new objects can be
created with small differences to existing ones.
OOP provides a good framework for code libraries where supplied software
components can be easily adapted and modified by the programmer. This is
particularly useful for developing graphical user interfaces.

49) What is the difference between class and objects?

Classes and objects are separate but related concepts. Every object belongs to a class and
every class contains one or more related objects.
A Class is static. All of the attributes of a class are fixed before, during, and after the
execution of a program. The attributes of a class dont change.

50) What are methods and fields?

A class can have members. Methods and fields are two important members of classes.
Member functions are known as methods and data members are known as fields.
51) Define Encapsulation?

The wrapping up of data and functions into a single unit is known as data encapsulation.
Encapsulation means combining data and related functions that use that data together and
providing it as a logical entity.

52) What is function overloading?

Function Overloading more than one method with the same name but different type of
parameters and/or number of parameters can be defined. Depending on the actual number
and/or static type of the parameters used, the compiler will resolve the call to the correct
method.

53) What is the difference between compile time and run time polymorphism?

Function overloading, operator overloading,and parametric types (templates in C++ or


generics in Java) are done at compile time.
Dynamic binding (virtual functions) is runtime polymorphism.

54) What is difference between C++ and Java?

C++ has pointers Java does not


Java is the platform independent as it works on any type of operating systems
Java has no pointers where c ++ has pointers
Java has garbage collection C++ does not.

55) What is the use of scope resolution operator?

A variable declared in an inner block cannot be accessed outside the block. To resolve this
problem the scope resolution operator is used. It can be used to uncover a hidden variable.
This operator allows access to the global version of the variable.

56) What are adaptor class?


Adaptor classes modify the existing interface of an existing class and provide a new
interface. In other words, an adapter class adapts a class for a specific purpose.

57) What is the use of default constructor?

A constructors that accepts no parameters is called the default constructor.If no user-defined


constructor exists for a class A and one is needed, the compiler implicitly declares a default
parameterless constructor A::A(). This constructor is an inline public member of its class. The
compiler will implicitly define A::A() when the compiler uses this constructor to create an
object of type A. The constructor will have no constructor initializer and a null body.

58) What is the difference between break and continue statement?

The break statement is used to terminate the control from the loop statements of the case-
switch structure. The break statement is normally used in the switch case loop and in each
case condition, the break statement must be used. If not, the control will be transferred to
the subsequent case condition also.
The continue statement is used to repeat the same operations once again even checks the
error.

59) What is the difference between class and structure?

By default, the members ot structures are public while that tor class is private.
Structures doesn't provide something like data hiding which is provided by the
classes.
Structures contains only data while class bind both data and member func

60) What is the difference between the terms overloading and overriding?

The term overriding refers to providing an alternative function definition of a virtual function
in a derived class. Overriding is useful for runtime polymorphism. With overloading, more
than one method definition with the same name (but with different types/number of
arguments) are provided, whereas in overriding, the methods with the same name are
provided with alternative definition in derived class

61) What are the types of inheritance?


Single inheritance
Multiple inheritance
Multi level inheritance
Hierarchical inheritance
Hybrid inheritance

62) What is method overriding?

Method overriding is a mechanism in which the sub class method overrides the base class
method. If the same function name is present in both the base class and the sub class then
the sub class method overrides the base class method.

63) What do you mean by pure virtual functions?

A pure virtual member function is a member function that the base class forces derived
classes to provide. Any class containing any pure virtual function cannot be used to create
object of its own type.

64) friend Function in C++.

If a function is defined as a friend function then, the private and protected data of class can
be accessed from that function. The complier knows a given function is a friend function by
its keyword friend. The declaration of friend function should be made inside the body of
class (can be anywhere inside class either in private or public section) starting with keyword
friend.

65) Virtual function:

If you want to execute the member function of derived class then, you can declare
display( ) in the base class virtual which makes that function existing in appearance only but,
you can't call that function. In order to make a function virtual, you have to add keyword
virtual in front of a function.

/* Example to demonstrate the working of virtual function in C++ programming. */

#include <iostream>
using namespace std;
class B
{
public:
virtual void display() /* Virtual function */
{ cout<<"Content of base class.\n"; }
};

class D1 : public B
{
public:
void display()
{ cout<<"Content of first derived class.\n"; }
};

class D2 : public B
{
public:
void display()
{ cout<<"Content of second derived class.\n"; }
};

int main()
{
B *b;
D1 d1;
D2 d2;

/* b->display(); // You cannot use this code here because the function of base class is
virtual. */

b = &d1;
b->display(); /* calls display() of class derived D1 */
b = &d2;
b->display(); /* calls display() of class derived D2 */
return 0;
}

Output

Content of first derived class.


Content of second derived class.

After the function of base class is made virtual, code b->display( ) will call the display( ) of
the derived class depending upon the content of pointer.

In this program, display( ) function of two different classes are called with same code which
is one of the example of polymorphism in C++ programming using virtual functions.

66) Define SQL.

SQL stands for Structured Query Language. It allows access, insert/update/delete records
and retrieve data from the database. Structured Query Language is a relational database
language, designed for managing data. The scope of SQL includes data query, including data,
deleting and modifying data and controlling the access to the data. A specialized language
for sending queries to database. Every specific application will have its own version of
implementing SQL features, but all SQL-capable database managers support a common
subset of SQL

67) What is an Entity-Relationship diagram?

It is a graphical representation of tables with the relationship between them. ER diagram is a


conceptual and abstract representation of data and entities. ER is a data modeling process,
which is to produce a conceptual schema of a system, often an RDBMS and the needs in top
down fashion. ER diagrams are derived by using this model.

68) What is RDBMS? Explain its features.

RDBMS stands for Relational Database Management System. It organizes data into related
rows and columns.

Features

It stores data in tables.


Tables have rows and column.
These tables are created using SQL.
And data from these tables are also retrieved using SQL

RDBMS is a database management system based on relational model defined by E.F.Codd.


Data is stored in the form of rows and columns. The relations among tables are also stored in
the form of the table.

Features:

- Provides data to be stored in tables


- Persists data in the form of rows and columns
- Provides facility primary key, to uniquely identify the rows
- Creates indexes for quicker data retrieval
- Provides a virtual table creation in which sensitive data can be stored and simplified query
can be applied.(views)
- Sharing a common column in two or more tables(primary key and foreign key)
- Provides multi user accessibility that can be controlled by individual users

69) Define Primary key and Foreign key.

A column or combination of columns that identify a row of data in a table is Primary Key.

A key in a table that identifies records in other table in called a foriegn key.

Primary key and unique key


Both are used to provide uniqueness of the column.
Primary key creates clustered key on the column by default whereas unique key creates non-
clustered index by default.
Primary doesn't allow NULL values whereas unique key can allow one NULL value.

Primary Key: Primary key is used for unique identification of each row in a table. Unique and
not null values only are accepted to persist in primary key.

Foreign Key: Foreign Key identifies a column with the primary key column of another table
(parent table) for storing data. The values in the foreign key must be the values of primary
key of other columns. Thus it ensures the data integrity correct data.

70) Define Trigger.

Triggers are similar to stored procedure except it is executed automatically when any
operations are occurred on the table. A Trigger is a code that associated with insert, update
or delete operations. The code is executed automatically whenever the associated query is
executed on a table. Triggers can be useful to maintain integrity in database.

71) Explain the types of relationships in database.

There are four relationships in database.

- One to One: One entity is associated with another entity. For Ex: Each employee is
associated with one department
- One to Many: One entity is associated with many other entities. For Ex: A company is
associated with all working employees in one branch/office/country.
- Many to One: Many entities are associated with only one entity. For Ex: Many employees
are associated with one project.
- Many to Many: Many entities are associated with many other entities. For Ex: In a company
many employees are associated with multiple projects(completed/existing), and at the same
time, projects are associated with multiple employees.

72) What is normalization?

Normalization is the way of organizing data in a database by removing redundancy and


inconsistent dependency.
Database normalization has the rules to be followed while creating databases.
Each rule is called as normal form.
First Normal form states - Remove duplicate column and identify each set of related data
with a primary key.
Second normal form - Create relationship between master and master detail tables using
foreign key.
Third normal form - Remove the fields that do not depend on the primary key.

It is the process of organizing data into related table.


To normalize database, we divide database into tables and establish relationships between
the tables.
It reduces redundancy. It is done to improve performance of query.

Normalization is the technique for designing database tables to eliminate data redundancy,
to safe guard the database against certain anomalies (structural problems). It is a step-by-
step breakdown of data structure complexity into simple structure that facilitates no loss to
information and relationship.

73) What are the benefits of normalizing database?

The benefits of normalization are:

- The process of searching, sorting and creating indexes is faster


- More tables can be derived for clear and needed tables to be designed
- Clustering indexes can be created which provides the flexibility in fine tuning queries.
- Less redundant data and fewer null values will make the database more compact.
- The indexes of tables make data modification commands execution much faster.
- If redundant data is not maintained, the execution of triggers is quicker.
- Normalization facilitates in reducing data modification anomalies

74) Explain DML and DDL statements.

DDL-Data Definition Language: DDL is the syntax of SQL for defining the way the database is
organized physically. Database meta data is created by DDL of SQL. The tables, views,
indexes, sequences, triggers, database users (by DBA) are well defined using DDL statement,
CREATE. Modification for the metadata or schema is done by ALTER command and removing
database objects is done by DROP command.

DML-Data Manipulation Language: DML statements, INSERT, DELETE, UPDATE AND SELECT
INTO are used for data manipulation, adding new rows, deleting unwanted rows and
changing data in the rows. These are known as SQL-change statements. DML does not
change the schema of database.

75) What is a join and explain different types of joins.

Joins are utilized to get the results from two or more tables. There are two types of joins
available.

1. Outer Join: Outer join has two categories left outer join and right outer join. In this join
functionality, two or more tables are joined by including blank rows in the specified side,
once the criterion satisfies.

The combination of left outer join and right outer join is simple outer join.
2. Inner Join: In this join functionality, two or more tables are joined by leaving the blank
rows for checking.

Other than these two joins, there are-


Natural Join: This join is the Cartesian product.
Equi Join: A condition includes an operator
NonEqui Join: They are conditional joins which does not use their conditions.

76) What are the restrictions applicable while creating views?

The following are the restrictions for creating views in RDBMS;

- Views can be created only in the current database.


- A computed value can not be changed in a view
- INSERT and DELETE statements may be used subject to the integrity constraints

Views can be created referencing tables and views only in the current database.
A view name must not be the same as any table owned by that user.
You can build views on other views and on procedures that reference views.
Rules or DEFAULT definitions can't be associated with views.
Only INSTEAD OF triggers can be associated with views.
The query that defines the view cannot include the ORDER BY, COMPUTE, or COMPUTE BY
clauses or the INTO keyword.
You cannot define full-text index definitions for views.
You cannot create temporary views
You cannot create views on temporary tables.

77) What are the uses of view?


1. Views can represent a subset of the data contained in a table; consequently, a view can
limit the degree of exposure of the underlying tables to the outer world: a given user may
have permission to query the view, while denied access to the rest of the base table.
2. Views can join and simplify multiple tables into a single virtual table
3. Views can act as aggregated tables, where the database engine aggregates data (sum,
average etc.) and presents the calculated results as part of the data
4. Views can hide the complexity of data; for example a view could appear as Sales2000 or
Sales2001, transparently partitioning the actual underlying table
5. Views take very little space to store; the database contains only the definition of a view,
not a copy of all the data which it presentsv.
6. Depending on the SQL engine used, views can provide extra security

78) What is a transaction? What are ACID properties?


Ans: A Database Transaction is a set of database operations that must be treated as whole,
means either all operations are executed or none of them.
An example can be bank transaction from one account to another account. Either both debit
and credit operations must be executed or none of them.
ACID (Atomicity, Consistency, Isolation, Durability) is a set of properties that guarantee that
database transactions are processed reliably.
79) What are the functions of operating system?

The operating system controls and coordinates the use of hardware among the different
processes and applications. It provides the various functionalities to the users. The following
are the main job of operating system.

Resource utilization
Resource allocation
Process management
Memory management
File management
I/O management
Device management

80) Explain Booting the system and Bootstrap program in operating system.

The procedure of starting a computer by loading the kernel is known as booting the system.

When a user first turn on or booted the computer, it needs some initial program to run. This
initial program is known as Bootstrap Program. It is stored in read-only memory (ROM) or
electrically erasable programmable read-only memory (EEPROM). Bootstrap program locates
the kernel and loads it into main memory and starts its execution.

81) Describe Main memory and Secondary memory storage in brief.

Main memory is also called random access memory (RAM). CPU can access Main memory
directly. Data access from main memory is much faster than Secondary memory. It is
implemented in a semiconductor technology, called dynamic random-access memory
(DRAM).

Main memory is usually too small to store all needed programs. It is a volatile storage device
that loses its contents when power is turned off. Secondary memory can stores large amount
of data and programs permanently. Magnetic disk is the most common secondary storage
device. If a user wants to execute any program it should come from secondary memory to
main memory because CPU can access main memory directly.
82) What is a Kernel?

- Kernel is the part of OS which handles all details of sharing resources and device handling.
- It can be considered as the core of OS which manages the core features of an OS.
- Its purpose is to handle the communication between software and hardware
- Its services are used through system calls.
- A layer of software called shell wraps around the Kernel.

83) Explain the basic functions of process management.

Important functions of process management are:

- Creation and deletion of system processes.


- Creation and deletion of users.
- CPU scheduling.
- Process communication and synchronization.

84) What do you know about interrupt?

- Interrupt can be understood as a signal from a device causing context switch.


- To handle the interrupts, interrupt handlers or service routines are required.
- The address of each Interrupt service routine is provided in a list which is maintained in
interrupt vector.

85) What do you mean by a zombie process?

- These are dead processes which are not yet removed from the process table.
- It happens when the parent process has terminated while the child process is still running.
This child process now stays as a zombie.

86) What is a named pipe?

- A traditional pipe is unnamed and can be used only for the communication of related
process. If unrelated processes are required to communicate - named pipes are required.
- It is a pipe whose access point is a file available on the file system. When this file is opened
for reading, a process is granted access to the reading end of the pipe. Similarly, when the
file is opened for writing, the process is granted access to writing end of the pipe.
- A named pipe is also referred to as a named FIFO or just FIFO.
87) What is a semaphore?

- A semaphore is a hardware or a software tag variable whose value indicates the status of a
common resource.
- Its purpose is to lock the common resource being used. A process which needs the
resource will check the semaphore to determine the status of the resource followed by the
decision for proceeding.
- In multitasking operating systems, the activities are synchronized by using the semaphore
techniques.

88) What is context switching?

- Context is associated with each process encompassing all the information describing the
current execution state of the process
- When the OS saves the context of program that is currently running and restores the
context of the next ready to run process, it is called as context switching.
- It is important for multitasking OS.

89) What is synchronization? What are the different synchronization mechanisms?

Synchronization means controlling access to a resource that is available to two or more


threads or process. Different synchronization mechanisms are:

- Mutex
- Semaphores
- Monitors
- Condition variables
- Critical regions
- Read/ Write locks

90) What is a critical section?

It is a section of code which can be executed only by one process at a time


91) What is the basic difference between pre-emptive and non-pre-emptive scheduling.

Pre-emptive scheduling allows interruption of a process while it is executing and taking the
CPU to another process while non-pre-emptive scheduling ensures that a process keeps the
CPU under control until it has completed execution.

92) What is a deadlock? What are the necessary conditions for deadlock to occur?

- It is a condition where a group of two or more waiting for the resources currently in use by
other processes of the same group.
- In this situation every process is waiting for an event to be triggered by another process of
the group.
- Since no thread can free up the resource a deadlock occurs and the application hangs

a.) At least one resource should be occupied in a non-sharable condition.


b.) A process holding at least one resource is waiting for more resources currently in use by
other processes.
c.) It is not possible to pre-empt the resource.
d.) There exists a circular wait for processes.

93) Name the different types of memory?

a.) Main memory also called primary memory or RAM


b.) Secondary memory or backing storage
c.) Cache
d.) Internal process memory

94) What are page frames? What are pages?

Page frames are the fixed size contiguous areas into which the main memory is divided by
the virtual memory.

-Pages are same sized pieces of logical memory of a program. Usually they range from 4 KB
to 8 KB depending on the addressing hardware of the machine.
- Pages improve the overall system performance and reduces requirement of physical
storage as the data is read in 'page' units.

95) Differentiate between logical and physical address.

- Physical addresses are actual addresses used for fetching and storing data in main memory
when the process is under execution.
- Logical addresses are generated by user programs. During process loading, they are
converted by the loader into physical address.

96) Explain thread. What are the advantage of using threads? What are the disadvantages
of using threads?

- It is an independent flow of control within a process.


- It consists of a context and a sequence of instructions for execution.

The main advantages of using threads are:

a.) No special communication mechanism is required.


b.) Readability and simplicity of program structure increases with threads.
c.) System becomes more efficient with less requirement of system resources.

The main disadvantages of using threads are:


- Threads can not be re-used as they exist within a single process.
- They corrupt the address space of their process.
- They need synchronization for concurrent read-write access to memory.

97) What is paging? Why paging is used?

OS performs an operation for storing and retrieving data from secondary storage devices for
use in main memory. Paging is one of such memory management scheme. Data is retrieved
from storage media by OS, in the same sized blocks called as pages. Paging allows the
physical address space of the process to be non contiguous. The whole program had to fit
into storage contiguously.

Paging is to deal with external fragmentation problem. This is to allow the logical address
space of a process to be noncontiguous, which makes the process to be allocated physical
memory

98) What is the meaning of physical memory and virtual memory?

Physical memory is the only memory that is directly accessible to the CPU. CPU reads the
instructions stored in the physical memory and executes them continuously. The data that is
operated will also be stored in physical memory in uniform manner.

Virtual memory is one classification of memory which was created by using the hard disk for
simulating additional RAM, the addressable space available for the user. Virtual addresses
are mapped into real addresses.
99) What are the difference between THREAD, PROCESS and TASK?

A program in execution is known as process. A program can have any number of processes.
Every process has its own address space.

Threads uses address spaces of the process. The difference between a thread and a process
is, when the CPU switches from one process to another the current information needs to be
saved in Process Descriptor and load the information of a new process. Switching from one
thread to another is simple.

A task is simply a set of instructions loaded into the memory. Threads can themselves split
themselves into two or more simultaneously running tasks

100) What is cache memory? Explain its functions

Cache memory is RAM. The most recently processing data is stored in cache memory. CPU
can access this data more quickly than it can access data in RAM. When the microprocessor
starts processing the data, it first checks in cache memory.

The size of each cache block ranges from 1 to 16 bytes. Every location has an index that
corresponds to the location which has data to access. This index is known as address. The
locations have tags; each contains the index and the datum in the memory that is needed to
be cached.

Cache memory is a high speed memory in the CPU that is used for faster access to data. It
provides the processor with the most frequently requested data. Cache memory increases
performance and allows faster retrieval of data.

101) Describe different job scheduling in operating systems.

Job scheduling schedules or decides which process will get to acquire the resource based on
some parameters.

FIFO- The process that comes first is executed first.

Shortest job First- The time taken to complete the job of all processes is computed and the
shortest length process is executed first.

Round Robin- Each process gets a time share for running and is later prevented to get the
next process running.

Priority scheduling- here, the process on highest priority gets the resource.

Das könnte Ihnen auch gefallen