Technical Interview Questions

Infosys Technical Interview Questions and Answers

1.Difference between C and C++?


 a) C follows the procedural programming paradigm while C++ is a multi-paradigm language (procedural  as well as object oriented)
 In case of C, importance is given to the steps or procedure of the program while C++ focuses on the  data rather than the process.
 Also, it is easier to implement/edit the code in case of C++ for the same reason.
 b) In case of C, the data is not secured while the data is secured (hidden) in C++
This difference is due to specific OOP features like Data Hiding which are not present in C.
c) C is a low-level language while C++ is a middle-level language
C is regarded as a low-level language (difficult interpretation & less user friendly) while C++ has features of both low-level (concentration on what's going on in the machine hardware) & high-level languages (concentration on the program itself) & hence is regarded as a middle-level language.
d) C uses the top-down approach while C++ uses the bottom-up approach
In case of C, the program is formulated step by step, each step is processed into detail while in C++, the base elements are first formulated which then are linked together to give rise to larger systems.
e) C is function-driven while C++ is object-driven
Functions are the building blocks of a C program while objects are building blocks of a C++ program.
f) C++ supports function overloading while C does not
Overloading means two functions having the same name in the same program. This can be done only in C++ with the help of Polymorphism (an OOP feature)
g) We can use functions inside structures in C++ but not in C.
In case of C++, functions can be used inside a structure while structures cannot contain functions in C.
h) The NAMESPACE feature in C++ is absent in case of C
C++ uses NAMESPACE which avoid name collisions. For instance, two students enrolled in the same university cannot have the same roll number while two students in different universities might have the same roll number. The universities are two different namespace & hence contain the same roll number (identifier) but the same university (one namespace) cannot have two students with the same roll number (identifier)
i) The standard input & output functions differ in the two languages
C uses scanf & printf while C++ uses cin>> & cout<< as their respective input & output functions
j) C++ allows the use of reference variables while C does not
Reference variables allow two variable names to point to the same memory location. We cannot use these variables in C programming.
k) C++ supports Exception Handling while C does not.
C does not support it "formally" but it can always be implemented by other methods. Though you don't have the framework to throw & catch exceptions as in C++.
2.What is null pointer?
When referring to computer memory, a null pointer is a command used to direct a software program or operating system to an empty location in the computer memory. Commonly, the null pointer is used to denote the end of a memory search or processing event. In computer programming, a null pointer is a pointer that does not point to any object or function.
A nil pointer is a false value. For example, 1 > 2 is a nil statement.
In the programming language C, NULL is an available command that can be used, where nil is an available command used in the Pascal programming language.

3.What are the 4 basics of OOP?  
 Abstraction, Inheritance, Encapsulation, and Polymorphism.

4.What you mean by Object Relational DBMS?
An object-relational database (ORD), or object-relational database management system (ORDBMS), is a database management system (DBMS) similar to a relational database, but with an object-oriented database model: objects, classes and inheritance are directly supported in database schemas and in the query language. In addition, just as with proper relational systems, it supports extension of the data model with custom data-types and methods.

5.Structural difference between bitmap and b-tree index ? 
Btree
It is made of branch nodes and leaf nodes. Branch nodes holds prefix key value along with the link to the leaf node. The leaf node in turn contains the indexed value and rowed.
Bitmap
It simply consists of bits for every single distinct value. It uses a string of bits to quickly locate rows in a table. Used to index low cardinality columns. 

6.what is database Schema?
The formal definition of database schema is a set of formulas (sentences) called integrity constraints imposed on a database.
7.what are the different levels of database schema?
Conceptual schema- a map of concepts and their relationships.
Logical schema- a map of entities and their attributes and relations
Physical schema- a particular implementation of a logical schema
Schema object- Oracle database object

8.what is difference between foreign key and reference key ?  
  Reference Key is the primary key that is referenced in the other table (linked via the other tables Foreign Key). Foreign Key is how you link the second table to the primary tables Primary Key (or Reference Key).

9.Tell me about DSN?
A Data Source Name (DSN) is the logical name that is used by Open Database Connectivity (ODBC) to refer to the drive and other information that is required to access data. The name is used by Internet Information Services (IIS) for a connection to an ODBC data source, such as a Microsoft SQL Server database. 

10.ifference between Clustered index and non clustered index ?   
Clustered Index
Only one per table
Faster to read than non clustered as data is physically stored in index order
Non Clustered Index
Can be used many times per table
Quicker for insert and update operations than a clustered index

11.What is WPF and WCF?
WPF/WCF application, need in .NET 3.0 Framework. This application will cover the following concepts:
WCF(Windows Communication Foundation)
The new service orientated attributes
The use of interfaces
The use of callbacks
Asynchronous delegates
Creating the proxy
WPF( Windows Presentation Foundation )
Styles
Templates
Animations
Databinding
Multithreading a WPF application
12.What is the difference between an EXE and a DLL?   
The term EXE is a shortened version of the word executable as it identifies the file as a program. On the other hand, DLL stands for Dynamic Link Library, which commonly contains functions and procedures that can be used by other programs.
10.Scenarios in which web application should be used and desktop application should be used?
13.Tell how to check whether a linked list is circular.
Create two pointers, each set to the start of the list. Update each as follows:
while (pointer1) {
pointer1 = pointer1->next;
pointer2 = pointer2->next; if (pointer2) pointer2=pointer2->next;
if (pointer1 == pointer2) {
print ("circular\n");
}
}

14.How can u increase the heap size in the memory?
If heap size set too low then you will get "out of memory" errors. If you set it too high then your system will hang or you will suffer poor performance because parts of the jvm will be swapped in and out of memory. A rule of thumb is that you should not set this parameter larger than about 80% of your free physical memory. On Windows XP machines you can determine your free physical memory from the Performance tab of the Task Manager application. 
Boosting the heap size parameter will allow you to read in larger file-based projects. It will also improve the performance of the database back-end since more memory is available for caching.In Java Set the maximum heap size, using the -Xmx command-line option, to a value that allows the application to run with 70% occupancy of the Java heap.The Java heap occupancy often varies over time as the load applied to the application varies. For applications where occupancy varies, set the maximum Java heap size so that there is 70% occupancy at the highest point, and set the minimum heap size, using the -Xms command line option, so that the Java heap is 40% occupied at its lowest memory usage. If these values are set, the Java memory management algortihms can modify the heap size over time according to the application load, while maintaining usage in the optimal area of between 40% and 70% occupancy.

15.Why is it difficult to store linked list in an array?
Both Arrays and Linked List can be used to store linear data of similar types.
Linked list provide dynamic size while the size of array is fixed, So we must know the upper limit on the number of elements in advance.
Linked lists have following drawbacks:
1) Random access is not allowed. We have to access elements sequentially starting from the first node. So we cannot do binary search with linked lists.
2) Extra memory space for a pointer is required with each element of the list.
3) Arrays have better cache locality that can make a pretty big difference in performance.

16.Different types of keys in SQL?
The different types of Keys in sql server are,
candidate key acts as a unique key. A unique key can be a Primary key. A candidate key can be a single column or combination of columns. Multiple candidate keys are allowed in a table.
Primary Key
To uniquely identify a row, Primary key is used.
A table allows only one Primary key
Primary key can be a single column or combination of columns.
Foreign Key
A foreign key in a table is a key which refer another table’s primary key . A primary key can be referred by multiple foreign keys from other tables. It is not required for a primary key to be the reference of any foreign keys. The interesting part is that a foreign key can refer back to the same table but to a different column. This kind of foreign key is known as “self-referencing foreign key”.
17.Explain about Joins, Views, Normalization, Triggers?
The JOIN keyword is used in an SQL statement to query data from two or more tables, based on a relationship between certain columns in these tables.
Tables in a database are often related to each other with keys.
view is a virtual table.A view contains rows and columns, just like a real table. The fields in a view are fields from one or more real tables in the database.
You can add SQL functions, WHERE, and JOIN statements to a view and present the data as if the data were coming from one single table.

Normalization is the process of efficiently organizing data in a database. There are two goals of the normalization process: eliminating redundant data (for example, storing the same data in more than one table) and ensuring data dependencies make sense (only storing related data in a table). Both of these are worthy goals as they reduce the amount of space a database consumes and ensure that data is logically stored. 
First Normal Form (1NF)
sets the very basic rules for an organized database:
Eliminate duplicative columns from the same table.
Create separate tables for each group of related data and identify each row with a unique column or set of columns (the primary key).
Second Normal Form (2NF)
further addresses the concept of removing duplicative data:
Meet all the requirements of the first normal form.
Remove subsets of data that apply to multiple rows of a table and place them in separate tables.
Create relationships between these new tables and their predecessors through the use of foreign keys.
Third Normal Form (3NF)
Meet all the requirements of the second normal form.
Remove columns that are not dependent upon the primary key.
Boyce-Codd Normal Form (BCNF or 3.5NF)
It also referred to as the "third and half (3.5) normal form", adds one more requirement:
Meet all the requirements of the third normal form.
Every determinant must be a candidate key.
Fourth Normal Form (4NF)
Meet all the requirements of the third normal form.
A relation is in 4NF if it has no multi-valued dependencies.
Remember, these normalization guidelines are cumulative. For a database to be in 2NF, it must first fulfill all the criteria of a 1NF database.
In a DBMS, a trigger is a SQL procedure that initiates an action (i.e., fires an action) when an event (INSERT, DELETE or UPDATE) occurs. Since triggers are event-driven specialized procedures, they are stored in and managed by the DBMS. A trigger cannot be called or executed; the DBMS automatically fires the trigger as a result of a data modification to the associated table. Triggers are used to maintain the referential integrity of data by changing the data in a systematic fashion. Each trigger is attached to a single, specified table in the database. 
18.what is the difference between socket and session?
The Socket is a Combination of Ip address and Port Number (in pairs)
Session is a Logical Connectivity between the source and destination 
19.What is a default gateway?
In organizational systems a gateway is a node that routes the traffic from a workstation to another network segment. The default gateway commonly connects the internal networks and the outside network (Internet). In such a situation, the gateway node could also act as a proxy server and a firewall. The gateway is also associated with both a router, which uses headers and forwarding tables to determine where packets are sent, and a switch, which provides the actual path for the packet in and out of the gateway.
20.Given an array of 1s and 0s arrange the 1s together and 0s together in a single scan of the array. Optimize the boundary conditions.
void main()
{
int A[10]={'0','1','0','1','0','0','0','1','0','1','0','0'};
int x=0,y=A.length-1;
while(x if(!A[x])
x++;
else if(A[y])
y--;
if(A[x] && !A[y])//here we are checking that stating index is having 1 and last index having 0 than swap values
A[x]=0,A[y]=1;
}
getch() 
}
21.Define Data Abstraction. What is its importance?
Abstraction is the process of recognizing and focusing on important characteristics of a situation or object and leaving/filtering out the un-wanted characteristics of that situation or object.
Abstraction is the basis for software development. Its through abstraction we define the essential aspects of a system. The process of identifying the abstractions for a given system is called as Modeling (or object modeling).
Three levels of data abstraction are:
1. Physical level : how the data is stored physically and where it is stored in database.
2. Logical level : what information or data is stored in the database. eg: Database administrator
3.View level : end users work on view level. if any amendment is made it can be saved by other name.

22.Write a program to swap two numbers without using a temporary variable.
void swap(int &i, int &j)
{
i=i+j;
j=i-j;
i=i-j;
}

23.Memory Allocation in C/C++
calloc() allocates a memory area, the length will be the product of its parameters(it has two parameters). calloc fills the memory with ZERO's and returns a pointer to first byte. If it fails to locate enough space it returns a NULL pointer.
malloc() allocates a memory area, length will be value entered as parameter.(it has one parameter). It does not initializes memory area
free() used to free the allocated memory(allocated through calloc and malloc), in other words, this used release the allocated memory
new also used to allocate memory on heap and initialize the memory using constructor
delete also used release memory allocated by new operator

24.Write output of the program?
int i=10; 
printf("%d%d%d",i,++i,i++);
Answer = 10 12 12

25.what is virtual function and pure virtual function?
Virtual function:-To achieve polymorphism, function in base class is declared as virtual , By declare virtual we make base class pointer to execute function of any derived class depends on content of pointer (any derived class address).
Pure Virtual Function :-This is function used in base class, and its defination has to be provide in derived class, In other pure virtual function has not defination in base it defined as :
virtual void fun()=0;
This means that this function not going to do anything, In case of pure virtual funtion derived function has to 
implement pure virtual function or redeclare it as pure virtual function

                                 

Wipro Technical Interview Questions


Memory management in C
The C programming language manages memory statically, automatically, or dynamically. 
Static-duration variables are allocated in main memory, usually along with the executable code of the program, and persist for the lifetime of the program
Automatic-duration variables are allocated on the stack and come and go as functions are called and return. 
For static-duration and automatic-duration variables, the size of the allocation is required to be compile-time constant.
Dynamic memory allocation in which memory is more explicitly (but more flexibly) managed, typically, by allocating it from the heap, an area of memory structured for this purpose.
In C, the library function malloc is used to allocate a block of memory on the heap. The program accesses this block of memory via a pointer that malloc returns. When the memory is no longer needed, the pointer is passed to free which deallocates the memory so that it can be used for other purposes.

Functionality of Operating System?
An operating system (OS) is a set of software that manages computer hardware resources and provides common services for computer programs. 
To act as interface between hardware and users, an operating system must be able perform the following functions:
1. Enabling startup application programs. Thus, the operating system must have:

- A text editor

- A translator

- An editor of links
2. The allocation of resources needed to execute programs is done by identifying: the programs that are running, the need for memory, peripheral devices and data protection requirements.

3. Facilities for data compression, sorting, mixing, cataloging and maintenance of libraries, through utility programs available.
4. Plan implementation works according to certain criteria, for efficient use of central processing unit.
5. Assisting implementation of programs through computer-user communication system, at both hardware and software level.
Examples of operating systems:BS2000,BS3000,DOS,PC-DOS,MS-DOS,LINUX,SOLARIS,MAC OS,UNIX,WINDOWS

What the use of IP address
An Internet Protocol address (IP address) is a numerical label assigned to each device (e.g., computer, printer) participating in a computer network that uses the Internet Protocol for communication.An IP address serves two principal functions: host or network interface identification and location addressing
What is difference between UNIQUE and PRIMARY KEY constraints?
A UNIQUE constraint is similar to PRIMARY key, but you can have more than one UNIQUE constraint per table. Contrary to PRIMARY key UNIQUE constraints can accept NULL but just once. If the constraint is defined in a combination of fields, then every field can accept NULL and can have some values on them, as long as the combination values is unique.

What are the steps involved in designing?
Project plan, Requirements, Design, Coding, Testing, Re-coding and design, Development, Maintenance.

what is the difference between interface and multiple interface?
Both an abstract class and an interface are specific types of computer objects that allow a programmer to loosely define one type of object as if it were another type, while retaining all of the object's original properties. While multiple different computer languages use one or both of these concepts, Java is the most well-known. Abstract classes and interfaces have a variety of similarities, but also incorporate significant differences in structure, syntax, and usage.

How can we delete Duplicate row in table?
SQL> delete from table_name where rowid not in (select max(rowid) from table group by duplicate_values_field_name);
When do you use SQL Profiler? 
  SQL Profiler utility allows us to basically track connections to the SQL Server and also determine activities such as which SQL Scripts are running, failed jobs etc..

What do you meant by active and passive objects?
Active objects are one which instigate an interaction which owns a thread and they are responsible for handling control to other objects. In simple words it can be referred as client.
Passive objects are one, which passively waits for the message to be processed. It waits for another object that requires its services. In simple words it can be referred as server.
What do you meant by static and dynamic modeling?
Static modeling is used to specify structure of the objects that exist in the problem domain. These are expressed using class, object and USECASE diagrams.
But Dynamic modeling refers representing the object interactions during runtime. It is represented by sequence, activity, collaboration and statechart diagrams. 
What is Program counter? 
Program counter holds the address of either the first byte of the next instruction to be fetched for execution or the address of the next byte of a multi byte instruction, which has not been completely fetched. In both the cases it gets incremented automatically one by one as the instruction bytes get fetched. Also Program register keeps the address of the next instruction.
Can you give an example of Stored Procedure? 
CREATE procedure - is a stored procedure, which is a saved collection of Transact-SQL statements that can take and return user-supplied parameters.
Benefits of Stored Procedures?
Reduced client/server traffic
Efficient reuse of code and programming abstraction
Enhanced security controls

Is XML case-sensitive? 
XML is case sensitive when uppercase and lowercase characters are treated differently.
Element type names, Attribute names, Attribute values, All general and parameter entity names, and data content (text), are case-sensitive. 
What is a Null object?
It is an object of some class whose purpose is to indicate that a real object of that class does not exist. One common use for a null object is a return value from a member function that is supposed to return an object with some specified properties but cannot find such an object. 
What is the property of class?
A property is a member that provides access to an attribute of an object or a class. Examples of properties include the length of a string, the size of a font, the caption of a window, the name of a customer, and so on.
Does a class inherit the constructors of its super class?
A class does not inherit constructors from any of its super classes.
If a class is declared without any access modifiers, where may the class be accessed?
A class that is declared without any access modifiers is said to have package access. This means that the class can only be accessed by other classes andinterfaces that are defined within the same package

What do you mean by Stack unwinding?
It is a process during exception handling when the destructor is called for all local objects between the place where the exception was thrown and where it is caught. 

Define precondition and post-condition to a member function.
Precondition: A condition that should return true when a member function is invoked. In order to use a function correctly a precondition should return true. If a precondition fails to hold, an operation will not take responsibility to perform any action of sensibility. For example, the interface invariants of stack class respond nothing about pushing even though the stack is already full. In this scenario, sinful () is a precondition for push operation.

Post-Condition: A condition that should return true before returning from an invoked function. In order to use a function correctly a post condition should return true. Taking a stack as an example, is empty () must necessarily be true after pushing the element into the stack when an element is pushed. The function is empty () is a post condition.

How can you sort the elements of the array in descending order? 
Syntax
B = sort(A)
B = sort(A,dim)
B = sort(...,mode)
[B,IX] = sort(A,...)
Description
B = sort(A) sorts the elements along different dimensions of an array, and arranges those elements in ascending order. 

If A is a ...                                                 sort(A) ...

Vector                                             Sorts the elements of A.

Matrix                                             Sorts each column of A.

Multidimensional array                     Sorts A along the first non-singleton dimension, and returns an array of sorted vectors.

Cell array of strings                         Sorts the strings in ascending ASCII dictionary order, and returns a vector cell array of strings. The sort is case-sensitive; uppercase letters appear in the output before                                             lowercase. You cannot use the dim or mode options with a cell array.
Sort - Sort array elements in ascending or descending order
Integer, floating-point, logical, and character arrays are permitted. Floating-point arrays can be complex. For elements of A with identical values, the order of these elements is preserved in the sorted list. When A is complex, the elements are sorted by magnitude, i.e., abs(A), and where magnitudes are equal, further sorted by phase angle, i.e., angle(A), on the interval [??, ?]. If A includes any NaN elements, sort places these at the high end.

B = sort(A,dim) sorts the elements along the dimension of A specified by a scalar dim.
B = sort(...,mode) sorts the elements in the specified direction, depending on the value of mode.
'ascend'
Ascending order (default)
'descend'
Descending order
[B,IX] = sort(A,...) also returns an array of indices IX, where size(IX) == size(A). If A is a vector, B = A(IX). If A is an m-by-n matrix, then each column of IX is a permutation vector of the corresponding column of A, such that
for j = 1:n
B(:,j) = A(IX(:,j),j); 
end
If A has repeated elements of equal value, the returned indices preserve the original ordering.
Example:Sort horizontal vector A:

A = [78 23 10 100 45 5 6];

sort(A)
ans =5 6 10 23 45 78 100
What is DOM?
The Document Object Model (DOM) is a cross-platform and language-independent convention for representing and interacting with objects in HTML, XHTML and XML documents.[1] Objects in the DOM tree may be addressed and manipulated by using methods on the objects. The public interface of a DOM is specified in its application programming interface (API).

How macro execution is faster than function ?
Difference between overloading and overriding in programming language is:

a) In overloading, there is a relationship between methods available in the same class whereas in overriding, there is relationship between a superclass method and subclass method.

b) Overloading does not block inheritance from the superclass whereas overriding blocks inheritance from the superclass.

c) In overloading, separate methods share the same name whereas in overriding, subclass method replaces the superclass.

d) Overloading must have different method signatures whereas overriding must have same signature.

19.what do you mean by realization in oops, what is persistent, transient object.

Name the operators that cannot be overloaded.?
There are 5 operators which cannot be overloaded. They are:

.* - class member access operator 

:: - scope resolution operator 

. - dot operator 

?:: - conditional operator 

Sizeof() - operator 

Note:- This is possible only in C++.

What is polymorphism?
In programming languages, polymorphism means that some code or operations or objects behave differently in different contexts.

For example, the + (plus) operator in C++:

4 + 5 <-- integer addition
3.14 + 2.0 <-- floating point addition
s1 + "bar" <-- string concatenation!

In C++, that type of polymorphism is called overloading.

Typically, when the term polymorphism is used with C++, however, it refers to using virtual methods, which we'll discuss shortly. 

What are the differences between a C++ struct and C++ class? 
The default member and base class access specifiers are different.
The C++ struct has all the features of the class. The only differences are that a struct defaults to public member access and public base class inheritance, and a class defaults to the private access specifier and private base class inheritance.

Before interview Please Refer this following programming Questions
Write a Program for :
1.palindrome for string and number 
2.String Reverse 
3.Sum,Average of all the number 
4.Prime  no 
5.Armstrong no 
6.fibonacci 
7.factorial 
8.prime number,

Palindrome  for string
#include
#include 

main()
{
char a[100], b[100];

printf("Enter the string to check if it is a palindrome\n");
gets(a);

strcpy(b,a);
strrev(b);

if( strcmp(a,b) == 0 )
printf("Entered string is a palindrome.\n");
else
printf("Entered string is not a palindrome.\n");

return 0;
}

Palindrome number in c
#include 

main()
{
int n, reverse = 0, temp;

printf("Enter a number to check if it is a palindrome or not\n");
scanf("%d",&n);

temp = n;

while( temp != 0 )
{
reverse = reverse * 10;
reverse = reverse + temp%10;
temp = temp/10;
}

if ( n == reverse )
printf("%d is a palindrome number.\n", n);
else
printf("%d is not a palindrome number.\n", n);

return 0;
}

Reverse a string using C programming
#include
#include

main()
{
char arr[100];

printf("Enter a string to reverse\n");
gets(arr);

strrev(arr);

printf("Reverse of entered string is \n%s\n",arr);

return 0;
}


/* Fibonacci Series c language */

#include

main()
{
int n, first = 0, second = 1, next, c;

printf("Enter the number of terms\n");
scanf("%d",&n);

printf("First %d terms of Fibonacci series are :-\n",n);

for ( c = 0 ; c < n ; c++ )
{
if ( c <= 1 )
next = c;
else
{
next = first + second;
first = second;
second = next;
}
printf("%d\n",next);
}

return 0;
}

Fibonacci series program in c using recursion
#include

int Fibonacci(int);

main()
{
int n, i = 0, c;

scanf("%d",&n);

printf("Fibonacci series\n");

for ( c = 1 ; c <= n ; c++ )
{
printf("%d\n", Fibonacci(i));
i++; 
}

return 0;
}

int Fibonacci(int n)
{
if ( n == 0 )
return 0;
else if ( n == 1 )
return 1;
else
return ( Fibonacci(n-1) + Fibonacci(n-2) );


Adding numbers in c using function
#include

long addition(long, long);

main()
{
long first, second, sum;

scanf("%ld%ld", &first, &second);

sum = addition(first, second);

printf("%ld\n", sum);

return 0;
}

long addition(long a, long b)
{
long result;

result = a + b;

return result;
}

                                                     

TCS Technical Interview Questions and Answers


This interview usually takes 45 minutes to an hour and may have one or two interviewers. One interviewer may focus on your communication skills, self-management skills and background by asking behavioral questions. The other will focus on your technical capabilities.

The Phone Interview

If TCS not coming to your school this fall, and you have probably submitted your resume online. You look great on paper and they would like to have an employment discussion with candidate. They will set up a mutually-convenient date and time for your phone interview. Your interviewer will assess your communication skills, self-management skills and background by asking behavioral questions. He / she may also assess your technical ability. If the phone interview goes well, you will be asked to join us for an in-person interview.

TCS Technical interview Questions
1. What is your strongest programming language (Java, ASP, C, C++, VB, HTML, C#, etc.)? 
   Point to remember: Before interview You should decide your Favorite programming language and be prepared based on that question.

2.Differences between C and Java?
1.JAVA is Object-Oriented while C is procedural.
2.Java is an Interpreted language while C is a compiled language.
3.C is a low-level language while JAVA is a high-level language.
4.C uses the top-down approach while JAVA uses the bottom-up approach.
5.Pointer go backstage in JAVA while C requires explicit handling of pointers.
6.The Behind-the-scenes Memory Management with JAVA & The User-Based Memory Management in C.
7.JAVA supports Method Overloading while C does not support overloading at all.
8.Unlike C, JAVA does not support Preprocessors, & does not really them.
9.The standard Input & Output Functions--C uses the printf & scanf functions as its standard input & output while JAVA uses the System.out.print & System.in.read functions.
10.Exception Handling in JAVA And the errors & crashes in C.

3.In header files whether functions are declared or defined?
Functions are declared within header file. That is function prototypes exist in a header file,not function bodies. They are defined in library (lib).

4.What are the different storage classes in C ?
There are four types of storage classes in C. They are extern, register, auto and static

5.What does static variable mean?
Static is an access qualifier. If a variable is declared as static inside a function, the scope is limited to the function,but it will exists for the life time of the program. Values will be persisted between successive 
calls to a function

6.How do you print an address ?
Use %p in printf to print the address.

7.What are macros? what are its advantages and disadvantages? 
Macros are processor directive which will be replaced at compile time.
The disadvantage with macros is that they just replace the code they are not function calls. similarly the advantage is they can reduce time for replacing the same values.
8.Difference between pass by reference and pass by value? 
Pass by value just passes the value from caller to calling function so the called function cannot modify the values in caller function. But Pass by reference will pass the address to the caller function instead of value if called function requires to modify any value it can directly modify.

9.What is an object?
Object is a software bundle of variables and related methods. Objects have state and behavior

10.What is a class?
Class is a user-defined data type in C++. It can be created to solve a particular kind of problem. After creation the user need not know the specifics of the working of a class.

11.What is the difference between class and structure?
Structure: Initially (in C) a structure was used to bundle different type of data types together to perform a particular functionality. But C++ extended the structure to contain functions also. 
The major difference is that all declarations inside a structure are by default public.
Class: Class is a successor of Structure. By default all the members inside the class are private.

12. What is ponter?
Pointer is a variable in a program is something with a name, the value of which can vary. The way the compiler and linker handles this is that it assigns 
a specific block of memory within the computer to hold the value of that variable.

13.What is the difference between null and void pointer?
A Null pointer has the value 0. void pointer is a generic pointer introduced by ANSI. Generic pointer can hold the address of any data type. 

14.what is function overloading 
   Function overloading is a feature of C++ that allows us to create multiple functions with the same name, so long as they have different parameters.Consider the following function:
   int Add(int nX, int nY)
    {
      return nX + nY;
    }

15.What is function overloading and operator overloading?

Function overloading: C++ enables several functions of the same name to be defined, as long as these functions have different sets of parameters (at least as far as their types are concerned). This capability is called function overloading. When an overloaded function is called, the C++ compiler selects the proper function by examining the number, types and order of the arguments in the call. Function overloading is commonly used to create several functions of the same name that perform similar tasks but on different data types.
Operator overloading allows existing C++ operators to be redefined so that they work on objects of user-defined classes. Overloaded operators are syntactic sugar for equivalent function calls. They form a pleasant facade that doesn't add anything fundamental to the language (but they can improve understandability and reduce maintenance costs).

16.what is friend function?
A friend function for a class is used in object-oriented programming to allow access to public, private, or protected data in the class from the outside.
Normally, a function that is not a member of a class cannot access such information; neither can an external class. Occasionally, such access will be advantageous for the programmer. Under these circumstances, the function or external class can be declared as a friend of the class using the friend keyword.

17.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.

18. Tell me something about abstract classes?
An abstract class is a class which does not fully represent an object. Instead, it represents a broad range of different classes of objects. However, this representation extends only to the features that those classes of objects have in common. Thus, an abstract class provides only a partial description of its objects.
19.What is the difference between realloc() and free()?
The free subroutine frees a block of memory previously allocated by the malloc subroutine. Undefined results occur if the Pointer parameter is not a valid pointer. If the Pointer parameter is a null value, no action will occur. The realloc subroutine changes the size of the block of memory pointed to by the Pointer parameter to the number of bytes specified by the Size parameter and returns a new pointer to the block. The pointer specified by the Pointer parameter must have been created with the malloc, calloc, or realloc subroutines and not been deallocated with the free or realloc subroutines. Undefined results occur if the Pointer parameter is not a valid pointer.

20.What is the difference between an array and a list?
Array is collection of homogeneous elements. List is collection of heterogeneous elements.
For Array memory allocated is static and continuous. For List memory allocated is dynamic and Random.
Array: User need not have to keep in track of next memory allocation.
List: User has to keep in Track of next location where memory is allocated.
Array uses direct access of stored members, list uses sequential access for members.

21.What are the differences between structures and arrays?
Arrays is a group of similar data types but Structures can be group of different data types

22.What is data structure?
A data structure is a way of organizing data that considers not only the items stored, but also their relationship to each other. Advance knowledge about the relationship between data items allows designing of efficient algorithms for the manipulation of data.
23. Can you list out the areas in which data structures are applied extensively?
Compiler Design,
Operating System,
Database Management System,
Statistical analysis package,
Numerical Analysis,
Graphics,
Artificial Intelligence,
Simulation

24.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.

25. what are the two integrity rules used in DBMS?
The two types of  integrity rules are referential integrity rules and entity integrity rules. Referential integrity rules dictate that a database does not contain orphan foreign key values. This means that 
A primary key value cannot be modified if the value is used as a foreign key in a child table. Entity integrity dictates that the primary key value cannot be Null.

26. Tell something about deadlock and how can we prevent dead lock?
In an operating system, a deadlock is a situation which occurs when a process enters a waiting state because a resource requested by it is being held by another waiting process, which in turn is waiting for another resource. If a process is unable to change its state indefinitely because the resources requested by it are being used by other waiting process, then the system is said to be in a deadlock.
Mutual Exclusion: At least one resource must be non-shareable.[1] Only one process can use the resource at any given instant of time.
Hold and Wait or Resource Holding: A process is currently holding at least one resource and requesting additional resources which are being held by other processes.
No Preemption: The operating system must not de-allocate resources once they have been allocated; they must be released by the holding process voluntarily.
Circular Wait: A process must be waiting for a resource which is being held by another process, which in turn is waiting for the first process to release the resource. In general, there is a set of waiting processes, P = {P1, P2, ..., PN}, such that P1 is waiting for a resource held by P2, P2 is waiting for a resource held by P3 and so on till PN is waiting for a resource held by P1.[1][7]

Thus prevention of deadlock is possible by ensuring that at least one of the four conditions cannot hold.
27. What is Insertion sort, selection sort, bubble sort( basic differences among the functionality of the three sorts and not the exact algorithms)

28. What is Doubly link list?
 A doubly linked list is a linked data structure that consists of a set of sequentially linked records called nodes. Each node contains two fields, called links, that are references to the previous and to the next node in the sequence of nodes. The beginning and ending nodes' previous and next links, respectively, point to some kind of terminator, typically a sentinel node or null, to facilitate traversal of the list. If there is only one sentinel node, then the list is circularly linked via the sentinel node. It can be conceptualized as two singly linked lists formed from the same data items, but in opposite sequential orders.
29.What is data abstraction?  what are the three levels of data abstraction with Example?
Abstraction is the process of recognizing and focusing on important characteristics of a situation or object and leaving/filtering out the un-wanted characteristics of that situation or object.
Lets take a person as example and see how that person is abstracted in various situations

A doctor sees (abstracts) the person as patient. The doctor is interested in name, height, weight, age, blood group, previous or existing diseases etc of a person
An employer sees (abstracts) a person as Employee. The employer is interested in name, age, health, degree of study, work experience etc of a person. 

Abstraction is the basis for software development. Its through abstraction we define the essential aspects of a system. The process of identifying the abstractions for a given system is called as Modeling (or object modeling).
Three levels of data abstraction are:
1. Physical level : how the data is stored physically and where it is stored in database.
2. Logical level : what information or data is stored in the database. eg: Database administrator
3.View level : end users work on view level. if any amendment is made it can be saved by other name.

30.What is command line argument?
Getting the arguments from command prompt in c is known as command line arguments. In c main function has three arguments.They are:
Argument counter
Argument vector
Environment vector

31.Advantages of a macro over a function?
Macro gets to see the Compilation environment, so it can expand #defines. It is expanded by the preprocessor. 

32.What are the different storage classes in C? 
Auto,register,static,extern

33.Which header file should you include if you are to develop a function which can accept variable number of arguments?
stdarg.h

34.What is cache memory ?
Cache Memory is used by the central processing unit of a computer to reduce the average time to access memory. The cache is a smaller, faster memory 
which stores copies of the data from the most frequently used main memory locations. As long as most memory accesses are cached memory locations, the average
latency of memory accesses will be closer to the cache latency than to the latency of main memory.

35.What is debugger?
A debugger or debugging tool is a computer program that is used to test and debug other programs
36. Const char *p , char const *p What is the difference between the above two?   
1) const char *p - Pointer to a Constant char ('p' isn't modifiable but the pointer is)
2) char const *p - Also pointer to a constant Char 
However if you had something like:
char * const p - This declares 'p' to be a constant pointer to an char. (Char p is modifiable but the pointer isn't)

37. What is Memory Alignment?  
Data structure alignment is the way data is arranged and accessed in computer memory. It consists of two separate but related issues: data alignment and data structure padding. 

38.Explain the difference between 'operator new' and the 'new' operator?   
The difference between the two is that operator new just allocates raw memory, nothing else. The new operator starts by using operator new to allocate memory, but then it invokes the constructor for the right type of object, so the result is a real live object created in that memory. If that object contains any other objects (either embedded or as base classes) those constructors as invoked as well.

39. Difference between delete and delete[]?    
The keyword delete is used to destroy the single variable memory created dynamically which is pointed by single pointer variable.
Eg: int *r=new(int)
the memory pointed by r can be deleted by delete r.
delete [] is used to destroy array of memory pointed by single pointer variable.
Eg:int *r=new(int a[10])
The memory pointed by r can be deleted by delete []r.

40. What is conversion constructor?    
A conversion constructor is a single-parameter constructor that is declared without the function specifier 'explicit'. The compiler uses conversion constructors to convert objects from the type of the first parameter to the type of the conversion constructor's class.To define implicit conversions, C++ uses conversion constructors, constructors that accept a single parameter and initialize an object to be a copy of that parameter.

41.What is a spanning Tree?
A spanning tree is a tree associated with a network. All the nodes of the graph appear on the tree once. A minimum spanning tree is a spanning tree organized so that the total edge weight between nodes is minimized.  

42. Why should we use data ware housing and how can you extract data for analysis with example?
If you want to get information on all the techniques of designing, maintaining, building and retrieving data, Data warehousing is the ideal method. A data warehouse is premeditated and generated for supporting the decision making process within an organization.
Here are some of the benefits of a data warehouse:

o With data warehousing, you can provide a common data model for different interest areas regardless of data's source. In this way, it becomes easier to report and analyze information.

o Many inconsistencies are identified and resolved before loading of information in data warehousing. This makes the reporting and analyzing process simpler.

o The best part of data warehousing is that the information is under the control of users, so that in case the system gets purged over time, information can be easily and safely stored for longer time period.

o Because of being different from operational systems, a data warehouse helps in retrieving data without slowing down the operational system.

o Data warehousing enhances the value of operational business applications and customer relationship management systems.

o Data warehousing also leads to proper functioning of support system applications like trend reports, exception reports and the actual performance analyzing reports.
Data mining is a powerful new technology to extract data for analysis.

43.Explain recursive function & what is the data structures used to perform recursion?
a) A recursive function is a function which calls itself.
b) The speed of a recursive program is slower because of stack overheads. (This attribute is evident if you run above C program.)
c) A recursive function must have recursive conditions, terminating conditions, and recursive expressions.

Stack data structure . Because of its LIFO (Last In First Out) property it remembers its caller so knows whom to return when the function has to return. Recursion makes use of system stack for storing the return addresses of the function calls. Every recursive function has its equivalent iterative (non-recursive) function. Even when such equivalent iterative procedures are written, explicit stack is to be used.

44.Differentiate between Complier and Interpreter?

An interpreter reads one instruction at a time and carries out the actions implied by that instruction. It does not perform any translation. But a compiler translates the entire instructions

45.What is scope of a variable?
Scope refers to the visibility of variables. It is very useful to be able to limit a variable's scope to a single function. In other words, the variable wil have a limited scope

46.What is an interrupt?
   Interrupt is an asynchronous signal informing a program that an event has occurred. When a program receives an interrupt signal, it takes a specified action. 

47.What is user defined exception in Java?
The keywords used in java application are try, catch and finally are used in implementing used-defined exceptions. This Exception class inherits all the method from Throwable class.

48.What is java Applet?
Applet is java program that can be embedded into HTML pages. Java applets runs on the java enables web browsers such as mozila and internet explorer. Applet is designed to run remotely on the client browser, so there are some restrictions on it. Applet can't access system resources on the local computer. Applets are used to make the web site more dynamic and entertaining. 

49.What do you know about the garbage collector?

Garbage collection is the systematic recovery of pooled computer storage that is being used by a program when that program no longer needs the storage. This frees the storage for use by other programs 
(or processes within a program). It also ensures that a program using increasing amounts of pooled storage does not reach its quota (in which case it may no longer be able to function). 

Garbage collection is an automatic memory management feature in many modern programming languages, such as Java and languages in the .NET framework. Languages that use garbage collection are often interpreted or run within a virtual machine like the JVM. In each case, the environment that runs the code is also responsible for garbage collection.

50.Write a Binary Search program
int binarySearch(int arr[],int size, int item)
{
int left, right, middle;
left = 0;
right = size-1;

while(left <= right)
{
middle = ((left + right)/2);

if(item == arr[middle])
{
return(middle);
}

if(item > arr[middle])
{
left = middle+1;
}
else
{
right = middle-1;
}
}

return(-1);
}

51.What are enumerations?
An enumeration is a data type, used to declare variable that store list of names. It is act like a database, which will store list of items in the variable. example: enum shapes{triangle, rectangle,...

52.What is static identifier?
The static identifier is used for initializing only once, and the value retains during the life time of the program / application. A separate memory is allocated for ‘static’ variables. This value can be used between function calls. The default value of an uninitialized static variable is zero. A function can also be defined as a static function, which has the same scope of the static variable. 

53.What is Cryptography?
Cryptography is the science of enabling secure communications between a sender and one or more recipients. This is achieved by the sender scrambling a message (with a computer program and a secret key) and leaving the recipient to unscramble the message (with the same computer program and a key, which may or may not be the same as the sender's key).
There are two types of cryptography: Secret/Symmetric Key Cryptography and Public Key Cryptography

54.What is encryption?

Encryption is the transformation of information from readable form into some unreadable form.
55.What is decryption?
Decryption is the reverse of encryption; it's the transformation of encrypted data back into some intelligible form.
56.What exactly is a digital signature?
Just as a handwritten signature is affixed to a printed letter for verification that the letter originated from its purported sender, digital signature performs the same task for an electronic message. A digital signature is an encrypted version of a message digest, attached together with a message.
                                          

                                            IBS Technical Interview Questions
what you know about c++?
Released in 1985, C++ is an object-oriented programming language created by Bjarne Stroustrup. C++ maintains almost all aspects of the C language, while simplifying memory management and adding several features - including a new datatype known as a class (you will learn more about these later) - to allow object-oriented programming. C++ maintains the features of C which allowed for low-level memory access but also gives the programmer new tools to simplify memory management. 
C++ used for: 
C++ is a powerful general-purpose programming language. It can be used to create small programs or large applications. It can be used to make CGI scripts or console-only DOS programs. C++ allows you to create programs to do almost anything you need to do. The creator of C++, Bjarne Stroustrup, has put together a partial list of applications written in C++.
What is an object?

Object is a software bundle of variables and related methods. Objects have state and behavior.
What do you mean by inheritance?

Inheritance is the process of creating new classes, called derived classes, from existing classes or base classes. The derived class inherits all the capabilities of the base class, but can add embellishments and refinements of its own.
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.
44. What is a scope resolution operator? 
A scope resolution operator (::), can be used to define the member functions of a class outside the class.
Anything wrong with this code? 
T *p = new T[10]; 
delete p; 
Everything is correct, Only the first element of the array will be deleted”, The entire array will be deleted, but only the first element destructor will be called.
What is Boyce Codd Normal form?

A relation schema R is in BCNF with respect to a set F of functional dependencies if for all functional dependencies in F+ of the form a-> , where a and b is a subset of R, at least one of the following holds:
* a- > b is a trivial functional dependency (b is a subset of a)
* a is a superkey for schema R

What is virtual class and friend class?

Friend classes are used when two or more classes are designed to work together and need access to each other's implementation in ways that the rest of the world shouldn't be allowed to have. In other words, they help keep private things private. For instance, it may be desirable for class DatabaseCursor to have more privilege to the internals of class Database than main() has.

How do you find out if a linked-list has an end? (i.e. the list is not a cycle)

You can find out by using 2 pointers. One of them goes 2 nodes each time. The second one goes at 1 nodes each time. If there is a cycle, the one that goes 2 nodes each time will eventually meet the one that goes slower. 
If that is the case, then you will know the linked-list is a cycle.

What is the difference between realloc() and free()?

The free subroutine frees a block of memory previously allocated by the malloc subroutine. Undefined results occur if the Pointer parameter is not a valid pointer. If the Pointer parameter is a null value, no action will occur. The realloc subroutine changes the size of the block of memory pointed to by the Pointer parameter to the number of bytes specified by the Size parameter and returns a new pointer to the block. The pointer specified by the Pointer parameter must have been created with the malloc, calloc, or realloc subroutines and not been deallocated with the free or realloc subroutines. Undefined results occur if the Pointer parameter is not a valid pointer.

What is function overloading and operator overloading?

Function overloading: C++ enables several functions of the same name to be defined, as long as these functions have different sets of parameters (at least as far as their types are concerned). This capability is called function overloading. When an overloaded function is called, the C++ compiler selects the proper function by examining the number, types and order of the arguments in the call. Function overloading is commonly used to create several functions of the same name that perform similar tasks but on different data types.

Operator overloading allows existing C++ operators to be redefined so that they work on objects of user-defined classes. Overloaded operators are syntactic sugar for equivalent function calls. They form a pleasant facade that doesn't add anything fundamental to the language (but they can improve understandability and reduce maintenance costs).

What is the difference between declaration and definition?

The declaration tells the compiler that at some later point we plan to present the definition of this declaration.
E.g.: void stars () //function declaration
The definition contains the actual implementation.
E.g.: void stars () // declarator
{
for(int j=10; j > =0; j--) //function body
cout << *;
cout <<>

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.

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;
}
}

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.

Write a program that ask for user input from 5 to 9 then calculate the average

#include "iostream.h"
int main() {
int MAX = 4;
int total = 0;
int average;
int numb;
for (int i=0; icout << "Please enter your input between 5 and 9: ";
cin >> numb;
while ( numb<5>9) {
cout << "Invalid input, please re-enter: ";
cin >> numb;
}
total = total + numb;
}
average = total/MAX;
cout << "The average number is: " <<>return 0;
}

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 can’t be accessed outside the class. However there is an exception can be using friend classes.
What is scope & storage allocation of global and extern variables? Explain with an example
Extern variables: belong to the External storage class and are stored in the main memory. extern is used when we have to refer a function or variable that is implemented in other file in the same project. 
The scope of the extern variables is Global.

Global variables: are variables which are declared above the main( ) function. These variables are accessible throughout the program. They can be accessed by all the functions in the program. Their default value is zero.

What is scope & storage allocation of static, local and register variables? Explain with an example.

Register variables: belong to the register storage class and are stored in the CPU registers. The scope of the register variables is local to the block in which the variables are defined. The variables which are used for more 
number of times in a program are declared as register variables for faster access.
Example: loop counter variables.
register int y=6;
Static variables: Memory is allocated at the beginning of the program execution and it is reallocated only after the program terminates. The scope of the static variables is local to the block in which the variables are defined.
Example:

#include 
void decrement(){
static int a=5;
a--;
printf("Value of a:%d\n", a);
}

int main(){
decrement();
return 0;
}
Local variables: are variables which are declared within any function or a block. They can be accessed only by function or block in which they are declared. Their default value is a garbage value.
What are the advantages of using unions?
Union is a collection of data items of different data types.
It can hold data of only one member at a time though it has members of different data types.

If a union has two members of different data types, they are allocated the same memory. The memory allocated is equal to maximum size of the members. The data is interpreted in bytes depending on which member is being accessed.

Example:

union pen {
char name;
float point;
};

Here name and point are union members. Out of these two variables, ‘point’ is larger variable which is of float data type and it would need 4 bytes of memory. Therefore 4 bytes space is allocated for both the variables. Both the variables have the same memory location. They are accessed according to their type.
Union is efficient when members of it are not required to be accessed at the same time.

Tell how to check whether a linked list is circular.
Create two pointers, each set to the start of the list. Update each as follows:
while (pointer1) {
pointer1 = pointer1->next;
pointer2 = pointer2->next; if (pointer2) pointer2=pointer2->next;
if (pointer1 == pointer2) {
print (\"circular\n\");
}
}

If a list is circular, at some point pointer2 will wrap around and be either at the item just before pointer1, or the item before that. Either way, it’s either 1 or 2 jumps until they meet.

What is virtual constructors/destructors?
Virtual destructors: If an object (with a non-virtual destructor) is destroyed explicitly by applying the delete operator to a base-class pointer to the object, the base-class destructor function (matching the pointer type) is called on the object.
There is a simple solution to this problem – declare a virtual base-class destructor. This makes all derived-class destructors virtual even though they don’t have the same name as the base-class destructor. Now, if the object in the hierarchy is destroyed explicitly by applying the delete operator to a base-class pointer to a derived-class object, the destructor for the appropriate class is called.

Virtual constructor: Constructors cannot be virtual. Declaring a constructor as a virtual function is a syntax error.
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.
Does c++ support multilevel and multiple inheritance?
Yes.
What is the difference between an ARRAY and a LIST?
Array is collection of homogeneous elements.
List is collection of heterogeneous elements.

For Array memory allocated is static and continuous.
For List memory allocated is dynamic and Random.

Array: User need not have to keep in track of next memory allocation.
List: User has to keep in Track of next location where memory is allocated.

Array uses direct access of stored members, list uses sequencial access for members.
What is a template?
Templates allow to create generic functions that admit any data type as parameters and return value without having to overload the function with all the possible data types. Until certain point they fulfill the functionality of a macro. Its prototype is any of the two following ones:
What is the difference between class and structure?
Structure: Initially (in C) a structure was used to bundle different type of data types together to perform a particular functionality. But C++ extended the structure to contain functions also. The major difference is that all declarations inside a structure are by default public.
Class: Class is a successor of Structure. By default all the members inside the class are private.
What is encapsulation?
Packaging an object’s variables within its methods is called encapsulation.
What is a COPY CONSTRUCTOR and when is it called?

A copy constructor is a method that accepts an object of the same class and copies it’s data members to the object on the left part of assignment:
class Point2D{
int x; int y;
public int color;
protected bool pinned;
public Point2D() : x(0) , y(0) {} //default (no argument) constructor
public Point2D( const Point2D & ) ;
};
Point2D::Point2D( const Point2D & p )
{
this->x = p.x;
this->y = p.y;
this->color = p.color;
this->pinned = p.pinned;
}
main(){yu
Point2D MyPoint;
MyPoint.color = 345;
Point2D AnotherPoint = Point2D( MyPoint ); // now AnotherPoint has color = 345
Program: To calculate the factorial value using recursion.
Program: To calculate the factorial value using recursion.
#include 
int fact(int n);

int main() {
int x, i;
printf("Enter a value for x: \n");
scanf("%d", &x);
i = fact(x);
printf("\nFactorial of %d is %d", x, i);
return 0;
}

int fact(int n) {
/* n=0 indicates a terminating condition */
if (n <= 0) {
return (1);
} else {
/* function calling itself */
return (n * fact(n - 1));
/*n*fact(n-1) is a recursive expression */
}
}

Output:
Enter a value for x:4

Factorial of 4 is 24
swap 2 numbers without using third variable?
#include 
void main()
{
int a,b;
printf("enter number1: ie a");
scanf("%d",a);
printf("enter number2:ie b ");
scanf("%d",b);
printf(value of a and b before swapping is a=%d,b=%d"a,b);
a=a+b;
b=a-b;
a=a-b;
printf(value of a and b after swapping is a=%d,b=%d"a,b);
}
Write a C++ Program to check whether a number is prime number or not?
#include
#include


void main()
{
clrscr();
int n,i,flag=1;
cout<<"Enter any number:";
cin>>n;


for(i=2;i<=n/2;++i)
{
if(n%i==0)
{
flag=0;
break;
}
}
if(flag)
cout<<"\n"< else
cout<<"\n"< getch();
}
Write a program in c to replace any vowel in a string with z?
// Replace all vowels in str with 'z' 
void replaceWithZ(char* str) { 
int i = 0; 
while(str[i] != 'z') { 
if(isVowel(str[i])) { 
str[i] = 'z'; 

++i; 


// Returns 1 if ch is a vowel, 0 otherwise 
int isVowel(const char ch) { 

switch(ch) { 
case 'a':case 'A': 
case 'e':case 'E': 
case 'i':case 'I': 
case 'o':case 'O': 
case 'u':case 'U': 
return 1; 

return 0; 

// Sample call 
int main() { 
char str[] = "HELLO"; 
printf("%s\n", str); 
replaceWithZ(str); 
printf("%s\n", str); 
return 0; 
}
Question from Java
What is the final keyword denotes?
 final keyword denotes that it is the final implementation for that method or variable or class. You can’t override that method/variable/class any more.
What is the significance of ListIterator?
 You can iterate back and forth.
What is the major difference between LinkedList and ArrayList?
 Linked List are meant for sequential accessing. ArrayList are meant for random accessing.
What is nested class?
 If all the methods of a inner class is static then it is a nested class.
What is inner class?
 If the methods of the inner class can only be accessed via the instance of the inner class, then it is called inner class.
What is composition?
 Holding the reference of the other class within some other class is known as composition.
What is aggregation?
It is a special type of composition. If you expose all the methods of a composite class and route the method call to the composite method through its reference, then it is called aggregation.
What are the methods in Object?
 clone, equals, wait, finalize, getClass, hashCode, notify, notifyAll, toString
Can you instantiate the Math class?
You can’t instantiate the math class. All the methods in this class are static. And the constructor is not public.
                   Electrical interview questions from AC & DC motor principle and working
what is the principle of motor?
Whenever a current carrying conductor is placed in an magnetic field it produce turning or twisting movement is called as torque.

Types of dc generator?
DC Generators are classified into two types 1)separatly excited DC generator 
2)self excited DC generator, which is further classified into; 1)series 2)shunt and 3)compound(which is further classified into cumulative and differential).
Which motor has high Starting Torque and Staring current DC motor, Induction motor or Synchronous motor?
DC Series motor has high starting torque. We can not start the Induction motor and Synchronous motors on load, but can not start the DC series motor without load.

Define stepper motor. What is the use of stepper motor?
The motor which work or act on the applied input pulse in it, is called as stepper motor. This stepper motor is under the category of synchronous motor, which often does not fully depend of complete cycle. It likes to works in either direction related to steps. for this purpose it mainly used in automation parts.

What is 2 phase motor?
A two phase motor is a motor with the the starting winding and the running winding have a phase split. e.g;ac servo motor.where the auxiliary winding and the control winding have a phase split of 90 degree.

Which type of A.C motor is used in the fan (ceiling fan, exhaust fan, padestal fan, bracket fan etc) which are find in the houses ?
Its Single Phase induction motor which mostly squirrel cage rotor and are capacitor start capacitor run.

Give two basic speed control scheme of DC shunt motor?
1. By using flux control method:in this method a rheostat is connected across the field winding to control the field current.so by changing the current the flux produced by the field winding can be changed, and since speed is inversely proportional to flux speed can be controlled
2.armature control method:in this method a rheostat is connected across armature winding by varying the resistance the value of resistive drop(IaRa) can be varied, and since speed is directly proportional to Eb-IaRathe speed can be controlled.

Difference between a four point starter and three point starter?
The shunt connection in four point starter is provided separately form the line where as in three point starter it is connected with line which is the drawback in three point starter.
What is the difference between synchronous generator & asynchronous generator?
In simple, synchronous generator supply's both active and reactive power but asynchronous generator(induction generator) supply's only active power and observe reactive power for magnetizing. This type of generators are used in windmills.

Why syn. generators are used for the production of electricity?
Synchronous machines have capability to work on different power factor (or say different imaginary power varying the field EMF. Hence syn. generators r used for the production of electricity.
Why is the starting current high in a DC motor?
In DC motors, Voltage equation is V=Eb-IaRa (V = Terminal voltage, Eb = Back emf in Motor, Ia = Armature current,Ra = Aramture resistance). At starting, Eb is zero. Therefore, V=IaRa, Ia = V/Ra ,where Ra is very less like 0.01ohm.i.e, Ia will become enormously increased.

What are the advantages of star-delta starter with induction motor?
The main advantage of using the star delta starter is reduction of current during the starting of the motor. Starting current is reduced to 3-4 times Of current of Direct online starting.(2). Hence the starting current is reduced , the voltage drops during the starting of motor in systems are reduced.

Why series motor cannot be started on no-load?
Series motor cannot be started without load because of high starting torque. Series motor are used in Trains, Crane etc.

Mention the methods for starting an induction motor?
The different methods of starting an induction motor
DOL:direct online starter
Star delta starter
Auto transformer starter
Resistance starter
Series reactor starter

What are Motor Generator Sets and explain the different ways the motor generator set can be used ? 
Motor Generator Sets are a combination of an electrical generator and an engine mounted together to form a single piece of equipment. Motor generator set is also referred to as a genset, or more commonly, a generator The motor generator set can used in the following different ways: 
1.Alternating current (AC) to direct current (DC)
2.DC to AC
3.DC at one voltage to DC at another voltage
4.AC at one frequency to AC at another harmonically-related frequency

Which type of motor is used in trains, what is the rating of supply used explain Working principal?
Dc series is in the trains to get high starting torque while starting of the trains and operating voltage is 1500v dc.

What are the Application of DC Motors in Thermal Power Plant?
In thermal power plants dc motors are employed for certain control and critical emergency operations which are supplied by dedicated batteries. DC motors operate as backup drives for normal ac drive systems when ac power supply to the plant is lost.
In thermal power plant, the dc motors finds applications for performing control functions such as

Turbine governor motor
Governor limit setting
Motor operated rheostats
Emergency lubrication for the turbines (main, boiler feed pumps)
Generator (H2 oil seal).
DC motor operated valves

DC motors employed in thermal plants are classified in to two types based on the type of application.

DC motors carrying out Control function 
Dc motors carrying out Emergency function

Control functions:This category consists of the turbine governor motor, governor limiting setting, motor operated rheostats, etc. These motors are small, about 1/8 hp or less. They are operated quite infrequently for short duration.
Emergency functions:This category consists of turbine-generator emergency (lubrication) bearing oil pumps and emergency seal oil pumps. Such pumps may also be provided for steam turbine drives of feedwater pumps, fans, and other large loads. The lack of lubrication during a shutdown without ac power will ruin the linings of the bearings and damage the shaft. 
Hydrogen seal oil pump is provided to prevent the escaping of hydrogen (for large turbine-generators hydrogen cooling is provided for efficient cooling) from the casing by providing a tight seal with high pressure oil

What are the Advantages & Disadvantages of Synchronous motors?

Advantage or Merits:

One of the major advantage of using synchronous motor is the ability to control the power factor. An over excited synchronous motor can have leading power factor and can be operated in parallel to induction motors and other lagging power factor loads thereby improving the system power factor. 
In synchronous motor the speed remains constant irrespective of the loads. This characteristics helps in industrial drives where constant speed is required irrespective of the load it is driving. It also useful when the motor is required to drive another alternator to supply at a different frequency as in frequency changes.
Synchronous motors can be constructed with wider air gaps than induction motors which makes these motors mechanically more stable.
In synchronous motors electro-magnetic power varies linearly with the voltage.
Synchronous motors usually operate with higher efficiencies ( more than 90%) especially in low speed and unity power factor applications compared to induction motors

Disadvantages or Demerits:

Synchronous motors requires dc excitation which must be supplied from external sources.
Synchronous motors are inherently not self starting motors and needs some arrangement for its starting and synchronizing.
The cost per kW output is generally higher than that of induction motors.
These motors cannot be used for variable speed applications as there is no possibility of speed adjustment unless the incoming supply frequency is adjusted (Variable Frequency Drives).
Synchronous motors cannot be started on load. Its starting torque is zero.
These motors have tendency to hunt.
When loading on the synchronous motor increases beyond its capability, the synchronism between rotor and stator rotating magnetic field is lost and motor comes to halt.
Collector rings and brushes are required resulting in increase in maintenance.
Synchronous motors cannot be useful for applications requiring frequent starting or high starting torques required.
                                     

Electronics Interview Questions


1. What is Electronic?
The study and use of electrical devices that operate by controlling the flow of electrons or other electrically charged particles.

2. What is communication?
Communication means transferring a signal from the transmitter which passes through a medium then the output is obtained at the receiver. (or)communication says as transferring of message from one place to another place called communication.


3. Different types of communications? Explain.
Analog and digital communication.
As a technology, analog is the process of taking an audio or video signal (the human voice) and translating it into electronic pulses. Digital on the other hand is breaking the signal into a binary format where the audio or video data is represented by a series of "1"s and "0"s.
Digital signals are immune to noise, quality of transmission and reception is good, components used in digital communication can be produced with high precision and power consumption is also very less when compared with analog signals.


4. What is sampling?
The process of obtaining a set of samples from a continuous function of time x(t) is referred to as sampling.


5. State sampling theorem.
It states that, while taking the samples of a continuous signal, it has to be taken care that the sampling rate is equal to or greater than twice the cut off frequency and the minimum sampling rate is known as the Nyquist rate.


6. What is cut-off frequency?
The frequency at which the response is -3dB with respect to the maximum response.


7. What is pass band?
Passband is the range of frequencies or wavelengths that can pass through a filter without being attenuated.


8. What is stop band?
A stopband is a band of frequencies, between specified limits, in which a circuit, such as a filter or telephone circuit, does not let signals through, or the attenuation is above the required stopband attenuation level.


9. Explain RF?
Radio frequency (RF) is a frequency or rate of oscillation within the range of about 3 Hz to 300 GHz. This range corresponds to frequency of alternating current electrical signals used to produce and detect radio waves. Since most of this range is beyond the vibration rate that most mechanical systems can respond to, RF usually refers to oscillations in electrical circuits or electromagnetic radiation.


10. What is modulation? And where it is utilized?
Modulation is the process of varying some characteristic of a periodic wave with an external signals.
Radio communication superimposes this information bearing signal onto a carrier signal.
These high frequency carrier signals can be transmitted over the air easily and are capable of travelling long distances.
The characteristics (amplitude, frequency, or phase) of the carrier signal are varied in accordance with the information bearing signal.
Modulation is utilized to send an information bearing signal over long distances.


11. What is demodulation?
Demodulation is the act of removing the modulation from an analog signal to get the original baseband signal back. Demodulating is necessary because the receiver system receives a modulated signal with specific characteristics and it needs to turn it to base-band.


12. Name the modulation techniques.
For Analog modulation--AM, SSB, FM, PM and SM
Digital modulation--OOK, FSK, ASK, Psk, QAM, MSK, CPM, PPM, TCM, OFDM


13. Explain AM and FM.
AM-Amplitude modulation is a type of modulation where the amplitude of the carrier signal is varied in accordance with the information bearing signal.
FM-Frequency modulation is a type of modulation where the frequency of the carrier signal is varied in accordance with the information bearing signal.


14. Where do we use AM and FM?
AM is used for video signals for example TV. Ranges from 535 to 1705 kHz.
FM is used for audio signals for example Radio. Ranges from 88 to 108 MHz.


15. What is a base station?
Base station is a radio receiver/transmitter that serves as the hub of the local wireless network, and may also be the gateway between a wired network and the wireless network.


16. How many satellites are required to cover the earth?
3 satellites are required to cover the entire earth, which is placed at 120 degree to each other. The life span of the satellite is about 15 years.


17. What is a repeater?
A repeater is an electronic device that receives a signal and retransmits it at a higher level and/or higher power, or onto the other side of an obstruction, so that the signal can cover longer distances without degradation.

18. What is an Amplifier?
An electronic device or electrical circuit that is used to boost (amplify) the power, voltage or current of an applied signal.


19. Example for negative feedback and positive feedback?
Example for –ve feedback is ---Amplifiers And for +ve feedback is – Oscillators


20. What is Oscillator?
An oscillator is a circuit that creates a waveform output from a direct current input. The two main types of oscillator are harmonic and relaxation. The harmonic oscillators have smooth curved waveforms, while relaxation oscillators have waveforms with sharp changes.


21. What is an Integrated Circuit?
An integrated circuit (IC), also called a microchip, is an electronic circuit etched onto a silicon chip. Their main advantages are low cost, low power, high performance, and very small size.


22. What is crosstalk?
Crosstalk is a form of interference caused by signals in nearby conductors. The most common example is hearing an unwanted conversation on the telephone. Crosstalk can also occur in radios, televisions, networking equipment, and even electric guitars.


23. What is resistor?
A resistor is a two-terminal electronic component that opposes an electric current by producing a voltage drop between its terminals in proportion to the current, that is, in accordance with Ohm's law:
V = IR.


25. What is inductor?
An inductor is a passive electrical device employed in electrical circuits for its property of inductance. An inductor can take many forms.


26. What is conductor?
A substance, body, or device that readily conducts heat, electricity, sound, etc. Copper is a good conductor of electricity.


27. What is a semi conductor?
A semiconductor is a solid material that has electrical conductivity in between that of a conductor and that of an insulator(An Insulator is a material that resists the flow of electric current. It is an object intended to support or separate electrical conductors without passing current through itself); it can vary over that wide range either permanently or dynamically.


28. What is diode?
In electronics, a diode is a two-terminal device. Diodes have two active electrodes between which the signal of interest may flow, and most are used for their unidirectional current property.


29. What is transistor?
In electronics, a transistor is a semiconductor device commonly used to amplify or switch electronic signals. The transistor is the fundamental building block of computers, and all other modern electronic devices. Some transistors are packaged individually but most are found in integrated circuits


30. What is op-amp?
An operational amplifier, often called an op-amp , is a DC-coupled high-gain electronic voltage amplifier with differential inputs[1] and, usually, a single output. Typically the output of the op-amp is controlled either by negative feedback, which largely determines the magnitude of its output voltage gain, or by positive feedback, which facilitates regenerative gain and oscillation.


31. What is a feedback?
Feedback is a process whereby some proportion of the output signal of a system is passed (fed back) to the input. This is often used to control the dynamic behaviour of the system.


32. Advantages of negative feedback over positive feedback.
Much attention has been given by researchers to negative feedback processes, because negative feedback processes lead systems towards equilibrium states. Positive feedback reinforces a given tendency of a system and can lead a system away from equilibrium states, possibly causing quite unexpected results.


33. What is Barkhausen criteria?
Barkhausen criteria, without which you will not know which conditions, are to be satisfied for oscillations.
“Oscillations will not be sustained if, at the oscillator frequency, the magnitude of the product of the
transfer gain of the amplifier and the magnitude of the feedback factor of the feedback network ( the magnitude of the loop gain ) are less than unity”.
The condition of unity loop gain -A? = 1 is called the Barkhausen criterion. This condition implies that
A?= 1and that the phase of - A? is zero.


34. What is CDMA, TDMA, FDMA?
Code division multiple access (CDMA) is a channel access method utilized by various radio communication technologies. CDMA employs spread-spectrum technology and a special coding scheme (where each transmitter is assigned a code) to allow multiple users to be multiplexed over the same physical channel. By contrast, time division multiple access (TDMA) divides access by time, while frequency-division multiple access (FDMA) divides it by frequency.
An analogy to the problem of multiple access is a room (channel) in which people wish to communicate with each other. To avoid confusion, people could take turns speaking (time division), speak at different pitches (frequency division), or speak in different directions (spatial division). In CDMA, they would speak different languages. People speaking the same language can understand each other, but not other people. Similarly, in radio CDMA, each group of users is given a shared code. Many codes occupy the same channel, but only users associated with a particular code can understand each other.


35. explain different types of feedback
Types of feedback:
Negative feedback: This tends to reduce output (but in amplifiers, stabilizes and linearizes operation). Negative feedback feeds part of a system's output, inverted, into the system's input; generally with the result that fluctuations are attenuated.
Positive feedback: This tends to increase output. Positive feedback, sometimes referred to as "cumulative causation", is a feedback loop system in which the system responds to perturbation (A perturbation means a system, is an alteration of function, induced by external or internal mechanisms) in the same direction as the perturbation. In contrast, a system that responds to the perturbation in the opposite direction is called a negative feedback system.
Bipolar feedback: which can either increase or decrease output.


36. What are the main divisions of power system?
The generating system,transmission system,and distribution system


37. What is Instrumentation Amplifier (IA) and what are all the advantages?
An instrumentation amplifier is a differential op-amp circuit providing high input impedances with ease of gain adjustment by varying a single resistor.


38. What is meant by impedance diagram. 
The equivalent circuit of all the components of the power system are drawn and they are interconnected is called impedance diagram.


39. What is the need for load flow study.
The load flow study of a power system is essential to decide the best operation existing system and for planning the future expansion of the system. It is also essential for designing the power system.


40. What is the need for base values? 
The components of power system may operate at different voltage and power levels. It will be convenient for analysis of power system if the voltage, power, current ratings of the components of the power system is expressed with referance to a common value called base value.



                    UST Global Technical interview Questions
Can you Mention some Application of C/C++?

Google-Some of the Google applications are also written in C++, including Google file system and Google Chromium.

Symbian OS- is also developed using C++. This is one of the most widespread OS’s for cellular phones. 

Apple – OS X -Few parts of apple OS X are written in C++ programming language. Also few application for iPod are written in C++.

Microsoft-Most of the big applications like Windows 95, 98, Me, 200 and XP are also written in C++. Also Microsoft Office, Internet Explorer and Visual Studio are written in Visual C++.

What are the different storage classes in C ?
There are four types of storage classes in C. They are extern, register, auto and static

What is an object?
Object is a software bundle of variables and related methods. Objects have state and behavior

What is a class?
Class is a user-defined data type in C++. It can be created to solve a particular kind of problem. After creation the user need not know the specifics of the working of a class.

1. What is a modifier?

A modifier, also called a modifying function is a member function that changes the value of at least one data member. In other words, an operation that modifies the state of an object. Modifiers are also 
known as ‘mutators’.

5. Define namespace.

It is a feature in C++ to minimize name collisions in the global name space. This namespace keyword assigns a distinct name to a library that allows other libraries to use the same identifier names without creating any name collisions. Furthermore, the compiler uses the namespace signature for differentiating the definitions.
What is data structure?

A data structure is a way of organizing data that considers not only the items stored, but also their relationship to each other. Advance knowledge about the relationship between data items allows designing of efficient algorithms for the manipulation of data

Can you list out the areas in which data structures are applied extensively?

Compiler Design,

Operating System,

Database Management System,

Statistical analysis package,

Numerical Analysis,

Graphics,

Artificial Intelligence,

Simulation

What is the difference between C and C++?

C follows the procedural programming paradigm 

C++ is a multi-paradigm language (procedural as well as object oriented)

In C language focus on procedure and steps.

C++ focuses on the data rather than the process

In C data hiding and data security is not possible. 

In C++Data hiding and data security is present.

C uses Top-Down approach

C++ uses Bottom-Up approach

C is a function driven programming language

C++ is a object driven programming language

C does not support overloading concept

C++ supports overloading concepts like operator overloading and function overloading

C does not support namespaces concept

C++ supports Namespaces concept.

C not support exception handling

C++ supports Exception Handling

C is structured programming language

C++ is object oriented programming language.

C does not support inheritance, reusability, polymorphism, data abstraction

C++ supports inheritance, reusability, polymorphism, data abstraction.

C language only support Early binding

C++ supports both Early and Late binding

C uses standard input, output functions like scanf and printf.

C++ uses input function cin and output function is cout.


What is the advantage of OOP?

**Simplicity

**modularity:

**modifiability

**extensibility

**maintainability

**re-usability

simplicity: software objects model real world objects, so the complexity is reduced and the program structure is very clear;

modularity: each object forms a separate entity whose internal workings are decoupled from
other parts of the system;

modifiability: it is easy to make minor changes in the data representation or the procedures in an OO program. Changes inside a class do not affect any other part of a program, since the only public interface that the external world has to a class is through the use of methods;

extensibility: adding new features or responding to changing operating environments can be solved by introducing a few new objects and modifying some existing ones;

maintainability: objects can be maintained separately, making locating and fixing problems
easier;

re-usability: objects can be reused in different programs.

How do you do dynamic memory allocation in C applications? 

In C, malloc, calloc and realloc are used to allocate memory dynamically. In C++, new(), is usually used to allocate objects.

List advantages and disadvantages of dynamic memory allocation vs. static memory allocation.?
Advantages:

Memory is allocated on an as-needed basis. This helps remove the inefficiencies inherent to static memory allocation (when the amount of memory needed is not known at compile time and one has to make a guess).

Disadvantages:
Dynamic memory allocation is slower than static memory allocation. This is because dynamic memory allocation happens in the heap area.
Dynamic memory needs to be carefully deleted after use. They are created in non-contiguous area of memory segment.
Dynamic memory allocation causes contention between threads, so it degrades performance when it happens in a thread.
Memory fragmentation.

What is Java?
Java is an object-oriented programming language developed initially by James Gosling and colleagues at Sun Microsystems. The language, initially called Oak (named after the oak trees outside Gosling's office), was intended to replace C++, although the feature set better resembles that of Objective C. Java should not be confused with JavaScript, which shares only the name and a similar C-like syntax. Sun Microsystems currently maintains and updates Java regularly. 

Can you have virtual functions in Java?

Yes, all functions in Java are virtual by default. This is actually a pseudo trick question because the word "virtual" is not part of the naming convention in Java (as it is in C++, C-sharp and VB.NET), so this 
would be a foreign concept for someone who has only coded in Java. Virtual functions or virtual methods are functions or methods that will be redefined in derived classes. 
What is a transient variable in Java?

A transient variable is a variable that may not be serialized. If you don't want some field to be serialized, you can mark that field transient or static.

What is thread?
A thread is an independent path of execution in a system.

What is multi-threading?
Multi-threading means various threads that run in a system. 

What is a dangling pointer?

pointers that do not point to a valid object of the appropriate type. Dangling pointers arise when an object is deleted or deallocated, without modifying the value of the pointer, so that the pointer still points to the memory location of the deallocated memory. As the system may reallocate the previously freed memory to another process, if the original program then dereferences the (now) dangling pointer, unpredictable behavior may result, as the memory may now contain completely different data. This is especially the case if the program writes data to memory pointed by a dangling pointer, as silent corruption of unrelated data may result, leading to subtle bugs that can be extremely difficult to find, or cause segmentation faults (*NIX) or general protection faults (Windows). 

What are the advantages and disadvantages of B-star trees over Binary trees.?

The major difference between B-tree and binary tres is that B-tree is a external data structure and binary tree is a main memory data structure. The computational complexity of binary tree is counted by the number of comparison operations at each node, while the computational complexity of B-tree is determined by the disk I/O, that is, the number of node that will be loaded from disk to main memory. The comparision of the different values in one node is not counted.

What will be printed as the result of the operation below:
main()
{
int x=20,y=35;
x=y++ + x++;
y= ++y + ++x;
printf(“%d%dn”,x,y);
}
Answer : 5794

What will be printed as the result of the operation below:
main()
{
int x=5;
printf(“%d,%d,%dn”,x,x< <2,x>>2);}

Answer: 5,20,1

What will be printed as the result of the operation below:
#define swap(a,b) a=a+b;b=a-b;a=a-b;void main()
{
int x=5, y=10;
swap (x,y);
printf(“%d %dn”,x,y);
swap2(x,y);
printf(“%d %dn”,x,y);
}

int swap2(int a, int b)
{
int temp;
temp=a;
b=a;
a=temp;
return 0;
}
Answer: 10, 5
10, 5

Comments