top of page
  • WeCare

Technical Questions - 01

Updated: Jun 4, 2020

I have created this while doing MCA(Pune University), Year 2004... might be outdated, but thought to share this with you

#technicalquestions #year2004 #mca

Q1) How do you write a program which produces its own source code as its output?

Ans) We can do this using FILE. Just open a file and give the path of the same file in which we are writing program and display contents of it using FILE pointer.

Q7) How do I access command-line arguments?

Ans) By using

Main (int argc,*char argv [])

Q8) How can I return multiple values from a function?

Ans) Using array. By passing base address of an array.

Q9) How can I invoke another program from within a C program?

Ans) Using #include<program name>

Q10) How can I access memory located at a certain address?

Ans) Using pointer.

Q15) What’s wrong with the call “fopen (“c:\newdir\file.dat”,”r”)”?

Ans) fopen () returns a file pointer, so it must assign to a file pointer.

Q16) What is the output of printf (“%d”)?

Ans) 0

Q18) What is the difference between “C structure” and “C++ structure”?

Ans) “C++ structure” includes class declaration whereas “C structure” doesn’t include class declaration because C++ is object oriented language.

Q19) What is the difference between “an assignment operator” and “a copy constructor”?

Ans) a member

Q20) What is the difference between “overloading” and “overriding”?

Ans) Methods with same name but different argument list are called Overloaded methods. Overriding is creation of a method in subclass that has the same name, number and type of arguments, as a method in super class.

Q23) What are different types of polymorphism?

Ans) Polymorphism is a feature that allows one interface to be used for general class of actions. The specific action is determined by the exact nature of the situation.

Two types of polymorphisms are achieved through

1. Function Overloading

2. Operator Overloading

1. Function Overloading

: In situation, the functions that share the same name are said to be overloaded, and the process is referred to as function overloading.

2. Operator Overloading

: In situation where the same operator can perform different operation depending upon the type of parameters passed to it is known as operator overloading.

Q24. What are virtual functions? How to implement virtual functions in C?

Ans) A virtual function is a member function that is declared within a base class

redefined by a derived class. To declare a function as virtual its declaration is preceded by the keyword virtual.

When a class containing a virtual function is inherited, the derived class redefines the virtual function to fit its own needs. In essence virtual function implements the “one interface multiple methods” philosophy that implements polymorphism.

Q25) What are different types of storage classes?

Ans) There are four storage class defined in C:

a. Automatic Storage Class

b. Register Storage Class

c. Static Storage Class

d. External Storage Class

Q26) What is Namespace?

Ans)A namespace is simply a declarative region in which various program elements can be stored. The purpose of namespace is to localize the names of the identifier to avoid name collisions. Namespaces help in the organization of large programs.

Q27) What are the types of STL containers?

Ans) Standard Template Library(STL) is a set of generic routines that you can use to manipulate data. STL containers are the objects that hold the other objects.

Types of STL Containers are

1. Sequence Container

: A sequence container has a linear list.

Eg. A Vector class defines dynamic array, deque creates double ended queue.

2. Associate Containers

: It allows efficient retrieval of values depending upon the keys.

Eg: Map provides values with unique value.

Q28) Difference between Vector and Array?

Ans)Vector implements dynamic array. It is similar to ArrayList but with two differences 1.Vector is synchronized

2. It contains many legacy methods that are not a part of a collections framework.

Q30) Can we generate a C++ source code from the binary file?

Ans) Yes we can generate a C++ source code from the binary file

Q31) What are inline functions?

Ans) In C++, you can create short functions that are not actually called; rather,

their code is expanded in line at the point of each invocation, such functions are called inline functions.

Q34) What is “strstream”?

Ans:- “strstream” is the array based i/o class which is used to create input/output streams that can perform both input and output.

Q36 Explain “passing by value”, ”passing by pointer” and “passing by reference.”.

Ans) In the pass by value method the value of each of the actual arguments in the calling function is copied into corresponding formal arguments of the called function. With this function, the changes made to formal arguments in the called function have no effect on the values of actual arguments in the calling function.

In the pass by reference method, the addresses of actual arguments in the calling function are copied into formal arguments of the called function. This means that using this address we would have and access to the actual arguments and hence we would be able to manipulate them.

Q38) Have you heard of a “mutable” keyword?

Ans) Sometimes there will be one or more member of class that you want a const function to modify even though you don’t want the function to be able to modify any of its other member function. You can accomplish this through the use of “mutable” keyword. That is, mutable member can be modified by a const

member function.

Q39) What is RTTI?

Ans) RTTI stands for Run Time Type Identification. Using RTTI, we can determine the type of an object during program execution. To obtain an objects type, use typeid. We must include the header file TYPEINFO.h in order to use typeid,

General form

typeid (object)

Q.41) What do you mean by Realization?

Ans) Realization is a semantic relationship between classifier wherein one classifier

Specifies a contract that another classifier guarantees to carryout.

Q.42)What is meant by Persistent, Transient object?

Ans) Persistent : These are used to store the state of the object permanently in a

Storage device.

Transient: Refers to the state of an object between two persistent states.

Q.43)What is the use of Operator Overloading?

Ans) To change the behavior of predefined set of operator we have to overload them.

Q.44) Does UML guarantee project success?

Ans) Yes.

Q.45) Difference: Activity Diagram and Sequence Diagram

Ans) Activity Diagram: Activity diagram is activity oriented. It shows the flow from activity to activity.

Sequence Diagram: A sequence diagram is time oriented.

Q.46) What is association?

Ans) An association is a group of links with common structure and common semantics.

All the links in an association connect objects from the same classes. An

association describes a set of potential links in the same way that a class describes

a set of potential objects.

Example: a person Works-for company. Works-for connects a person to company.

Q.47) How to resolve many to many relationship?

Ans) Many-to-Many relationship cannot be directly converted into database tables and relationships

Q.48) How do you represent static members and abstract classes in Class Diagram?

Ans) Static members are represented using underline.

Abstract classes are expressed by providing the name using italics style.

Q 49) What does a static variable mean?

Ans. Static variables are the variables that retain their values throughout the life of the program . As a result, if a function is exited and then re-entered later, the static

variables defined within that function will retain their former values. This

feature allows functions to retain their information permanently throughout the

execution of the program.

Q.50) What is a pointer?

Ans) A pointer is a variable that represents the location of a data item. It stores the

memory address of another variable. Since it is a variable, the pointer variable

itself will be stored at some address location.

Q.51) What is a structure?

Ans) A structure contains a number of data types grouped together. These data types

may or may not be of the same type.




struct book


char name;

float price;

int pages;



Q.53> In header files whether functions are declared or defined?

Ans) In header files all library functions are declared.

Q.55) What are macros? What are its advantages and disadvantages?

Ans) A macro is a small sub-program which contains executable code and is similar

to a function. Whenever a macro name occurs in a program the preprocessor

substitutes the code of the macro at that position. The execution is faster since

time is not wasted in function call and return.


1. >Their arguments are not case sensitive. Therefore we can pass any numeric

Variable type to an argument macro that expects a numeric argument.

2. > Argumented macros execute much faster as compared to their corresponding functions.

Q.60) Difference between array and linked list?



Linked List

1. Uses static memory allocation.

1. Uses dynamic memory allocation.

2. An array is a static data structure i.e. its

size remains fixed.

2. It is a dynamic data structure i.e. its size

varies during run time.

3. If the number of elements are not known

in advance, memory may be wasted if

less number if elements are stored and

it is not possible to increase array during

run time.

3. Memory is allocated only when a new

element has to be stored and it is freed

when not required.

4. No insertions or deletions are possible.

4. An element can be inserted or deleted

from any position.

5. It is sequential method of storage.

5. Non sequential storage.

6. Provides random access to any element.

6. Provides only sequential access.

Q61) What is the use of operator overloading?

Ans) An additional task can be assigned to an existing operator by overloading them.

Q62) What is association?

Ans) An association describes a group of links with common structures and semantics. A link I a physical or conceptual connection between object instances.

Q64) What is a pointer?

Ans) A pointer is a variable is capable of storing address of another variable, this variable itself might be another pointer

Q65) What is a structure?

Ans) Structure is a collection of variables of different data types.A memory is allocated to structure when its object is created .

Q66)What are the differences between structures and arrays?

Ans)Arrays can store a number of pieces of information of the same type whereas structures contains a number of datatypes grouped together.

Q67) In header files whether functions are declared or defined?

Ans) - Declared

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

Ans) Macro is a facility provided by language preprocessor , it replaces text defined by macro definition at the place of macro call. This helps programmer in avoiding functions and save time in writing repeatative code at various place .

The programs return in macros run faster than program return with functions.Disadvantage is that the above speed efficiency is achieved at cost of memory i.e. target generated in case of macros is bigger in size compare to target code generated in case of functions.

Q69) Difference between pass by value and pass by references?

Ans)- In call by value each of the actual arguments in the calling function is copied into corresponding formal arguments of the called function whereas in call by reference the address of actual arguments in the calling function are copied into formal arguments of called function.

Q70) Where are the auto variables stored?

Ans) - Main memory

Q71) Difference between arrays and linked list?

Ans)The elements of an array occupy contiguous memory location whereas those of a linked list are not constrained to be stored in adjacent location

Q72) What does static variables mean?

Ans) It retains its original value.

Q 81) Difference between strdup and strcpy ?

Ans) strdup duplicates a string . while strcpy copies given no of characters of one string to another .

Q 82) What is the use of Typedef ?

Ans) Typedef is used to redefine the name of an existing variable type .

Q 83) What are register variables ? What are advantage of using register variable ?

Ans) Register variables are the variable that are directly stored in cpu register and hence can be accessed fast.

Q 84) What is recursion?

Ans) A statement within a body of function calls itself then the function is recursive.

Q 85)What is the difference between string and array?

Ans) Array can be a array of integer or array of characters

But a string is array of character only.

Q 86)What is the far Pointer ? Where we use it?

Ans) A far pointer is a 32 bit pointer that contains both segment address and offset address.

By using far pointers we can have multiple code segments, which in turn allow you to have programs longer than 64kb.

Q 87)In a header file whether functions are declared or defined ?

Ans) In a header file functions are declared and not defined .

Q 88) Differentiate between for loop and while loop ?

Ans) In for loop, the initialization , condition and incrementation is done in one stmt while in while loop only the condition is present

For is used if no of iteration is done in advanced and while loop is used when iteration is unknown.

Q 89) What are different storage classes in C ?


1) Register

2) Automatic

3) External

4) Static

Q 90) Difference between Union and structures ?

Ans) A union is essentially a structure in which all of the field overlays each other Unlike structure in Union you can use only one field at a time.

Q 91) Describe the storage allocation and scope of global, static, local, register variable?


1> Register

Storage Allocation – CPU Register

Scope – Local to block in which variable is defined

Life – Till the control remains in the block

Default Initial value – garbage

2> Static

Storage Allocation – MEMORY

Scope – Local to block in which variable is defined

Life –value of variable call persist between different functional call

Default Initial value – Zero


Storage Allocation – Memory

Scope –Global

Life –As long as program execution doesn’t comes to end

Default Initial value – Zero


Storage Allocation –Memory.

Scope – Local to block in which variable is defined.

Life –Till the control remains within the block in which variable is defined.

Default Initial value – Zero.

Q 92) Write down equivalent pointer expression for referring the same element

a[i][j][k][l] ?


Q 93) Difference between gets() and fgets()?

Ans) fgets() reads the string from the file

Gets() reads the reads a line from keyboard

Q 94)What is far , near and huge pointer ? How many bytes are occupied by them ?

Ans) Far pointer – It is a 32 bit pointer that contains both segment address and offset address.

Huge pointer - It is also 32 bit pointer again containing both segment address and offset address.

Near pointer – it is 16 bits long. It uses the current content of CS(Code segment) register or current content of DS(data segment) registers.

101) What is near, far and huge pointers? How many bytes do they occupy?

Ans) There are 2 types of 32 bit pointers in c Near and Far pointer.

By using these pointers we can directly access memory to interact hardware before starting hardware programming in C.

Huge pointers are those used my Microsoft to make your machine run out of memory. Usually the words "class" and "constructor" are found to be related to HUGE pointers.

1. far pointer. 2. Huge Pointer.

Far pointers are not normalized.

Huge pointers are normalized.

near uses 4 bytes

far uses 2 bytes Example: far *ptr;

huge uses 1 byte

102) How would you obtain segment and offset addresses from far address of a memory location?

Ans) Segment is pointer/2, Offset is pointer + 64K.

These are obviously sub fields of the far Address, so you mask off the bits of the address that you don't want.

103) Are the expressions arr and &arr same for an array integers?

Ans) Yes

104) Does mentioning the array name gives the base address in all the contexts?

Ans) Yes

107) Can a structure contain a Pointer to itself?

Ans) Yes, but a problem can arise if you try to use typedefs

109) How are Structures passing and returning implemented by the compiler?

Ans) When structures are passed as arguments to functions, the entire structure is typically pushed on the stack, using as many words as are required. (Programmers often choose to use pointers to structures instead, precisely to avoid this overhead.) Some compilers merely pass a pointer to the structure, though they may have to make a local copy to preserve pass-by-value semantics.

Structures are often returned from functions in a location pointed to by an extra, compiler-supplied ``hidden'' argument to the function. Some older compilers used a special, static location for structure returns, although this made structure-valued functions non-reentrant, which ANSI C disallows.

110)How can we read/write Structures from/to data files?


                                     fwrite(&somestruct, sizeof somestruct, 1, fp);

and a corresponding fread invocation can read it back in. What happens here is that fwrite receives a pointer to the structure, and writes (or fread correspondingly reads) the memory image of the structure as a stream of bytes. The sizeof operator determines how many bytes the structure occupies. (The call to fwrite above is correct under an ANSI compiler as long as a prototype for fwrite is in scope, usually because <stdio.h> is #included. However, data files written as memory images in this way will not be portable, particularly if they contain floating-point fields or pointers. The memory layout of structures is machine and compiler dependent. Different compilers may use different amounts of padding, and the sizes and byte orders of fundamental types vary across machines. Therefore, structures written as memory images cannot necessarily be read back in by programs running on other machines (or even compiled by other compilers), and this is an important concern if the data files you're writing will ever be interchanged between machines.

Also, if the structure contains any pointers (char * strings, or pointers to other data structures), only the pointer values will be written, and they are most unlikely to be valid when read back in. Finally, note that for widespread portability you must use the "b" flag when opening the files.

A more portable solution, though it's a bit more work initially, is to write a pair of functions for writing and reading a structure, field-by-field, in a portable (perhaps even human-readable) way.

Q 111) What is the difference between an enumeration and a set of pre-processor # defines?

Ans) There is little difference. The C Standard says that enumerations have integral type and that enumeration constants are of type int, so both may be freely intermixed with other integral types, without errors. (If, on the other hand, such intermixing were disallowed without explicit casts, judicious use of enumerations could catch certain programming errors.)

Some advantages of enumerations are that the numeric values are automatically assigned, that a debugger may be able to display the symbolic values when enumeration variables are examined, and that they obey block scope. (A compiler may also generate nonfatal warnings when enumerations are indiscriminately mixed, since doing so can still be considered bad style even though it is not strictly illegal.) A disadvantage is that the programmer has little control over those nonfatal warnings; some programmers also resent not having control over the sizes of enumeration variables.

Q 112) What do the ‘c’ and ‘v’ in argc and argv stand for?

Ans) ’ c’ stands for count

’v’ stands for vector

Q 113) Are the variables argc and argv local to main?

Ans) Yes. All function parameters are local to that function.

Example void main(int argc , char *argv[])

No. Not in the following code


Double argc; int argv; int main(int x, char**y)

{ return 0; }

Clearly, argc and argv are not local to main().

114) What is the maximum combined length of command line arguments including the space between adjacent arguments?

Ans) 128 for DOS 260 for Win16 255 for Win32

115)If we want that any wildcard characters in the command line argument should be appropriately expanded, are we required to make any special provision? If yes, which?

Ans) If the shell from which you invoked the program does not expand wildcards for you, you will have to expand those wildcards manually. How you do so depends on what utilities are available to you. There's no facility in the standard library. C has no knowledge of "wildcards". You'll have to implement the entire expansion algorithm yourself or use a third-party solution.

116) Does there exist any way to make the command line argument s available to other functions without passing them as arguments to the function?


Yes. Create global variables and assign the argc and argv variables to those global variables


Yes. For example,

#include <stdio.h> char **argv_copy;

int func(void) { return *argv_copy > 0; }

int main(int argc, char **argv)

{ argv_copy = argv; if (func) puts(argv[0]); return 0; }

117) What are the bit fields? What is the use of bit fields in Structure Declaration?

Ans)Bit fields are typically used in machine-dependent programs that must force a data Structure to correspond to a fixed hardware representation. The precise manner in which components (and specifically bit fields) are packed into a Structure in implementation-dependent but is predictable for each implementation. The intent is that bit fields should be packed as tightly as possible in a Structure.

Bit fields can be used to save space in structures having several binary flags or other small fields.

118)To which numbering system can the binary number 1101100100111100 be easily converted to?

Ans) floating point

119)Which bitwise operator is suitable for checking whether a particular bit is on or off?


The ‘&’ operator

The ‘OR’ operator


120)Which bitwise operator is suitable for turning off a particular bit in a number?


The bitwise AND (&) operator

Example: e1 &=e1;

Q121) Which bit wise operator is suitable for putting on a particular bit in a number?

Ans)The ‘|’ bit wise operator is suitable for putting a particular bit in a number

Q122) Which bit wise operator is suitable for checking whether a particular bit is on or off?

Ans) The ‘&’ operator is suitable for checking whether a particular bit is on ar off

Q123) Which one is equivalent to multiplying by 2: Left shifting a number by 1 or left shifting an unsigned int or char by 1?

Ans)Left shifting an unsigned int or char by 1 is always equivalent to multiplying it by 2.

Q124)Write a program to compare two strings without using the strcmp() function.

Ans) #include<stdio.h>

void main()


char *s1,*s2;

int i,j;




if(strlen(s1) != strlen(s2))

printf("Strings not equals");







printf("Strings are equals");


printf("Strings are not equals");




Q125) Write a program to concatenate two strings.

Ans) #include<stdio.h>

void main()


char *s1,*s2;

int l,i;










Q126) Write a program to interchange 2 variables without using the third one.

#include <stdio.h>

void main()


int i,j;


printf("\n Enter value if i and j : ");

scanf("%d %d",&i,&j);

printf("\n Values of i and j before swapping are %d and %d respectively",i,j);




printf("\n Values of i and j after swapping are %d and %d respectively",i,j);



Q127) Write a program for String Reversal & Palindrome check.

String Reversal

#include <stdio.h>

#include <conio.h>

void main()


int i=0,j=0;

char *str;


printf("Enter Your string : ");





printf("Reverse string is :\n");







void main()


char *s;

int l,i,j;




for(i=0,j=(l-1);i<l && j>0;i++,j--)


if(*(s+i) != *(s+j))


printf("Not Palindrom");








Q128) Write a program to find the Factorial of a number.

#include <stdio.h>

#include <conio.h>

void main()


int i,j=0,k=1,fib=0,n;


printf("How many terms you want to print : ");


printf("The Fibonacci series is as follows :\n");










Q129) Write a program to generate the Fibonacci Series.

#include <stdio.h>

#include <conio.h>

void main()


long i,n,fact=1;


printf("\n Enter Your Number : ");




printf("\n The Factorial of %ld is %ld",n,fact);



Q130) Write a program which employs Recursion.

#include <stdio.h>

void main()


int n,fact;


printf("\n Enter any number : ");



printf("\n Factorial of %d is %d ",n,fact);



rec_fact(int x)


int f;


return 1;


f = x * rec_fact(x-1);

return f;


Q131) Write a program which uses Command Line Arguments.


void main(int argc,char *argv[])


int i;


printf("Number of Arguments %d",argc);


printf("\nArgument number %d is %s",i+1,*(argv+i));



Q132) Write a program which uses functions like strcmp(), strcpy(), etc.


void main()


char *s1,*s2;




printf("%s",strcmp(s1,s2)?"Strings are not equal":"Strings are equal");





Q133) What are the advantages of using tydef in a program?

There are three main reasons for using typedefs:

(a) It makes writing of complicated declarations a lot easier. This helps in eliminating a lot of cluter in the program.

(b) It helps in achieving portability in programs. That is, if we use ‘typedefs’ for data types that are machine-dependent, only the ‘typedefs’ need change when program is moved to a new machine platform.

(c) It helps in providing a better documentation for a program. For example, a node of a doubly linked list is better understood as ptrolist rather than just a pointer to a complicated structure.

Q134) Hoe would you dynamically allocate a one-dimensional and two-dimensional array of integers?


#include <alloc.h>

#define MAX 10



int *p,i;

p=(int *)malloc(MAX * sizeof(int));








#include <alloc.h>

#define MAXROW 3

#define MAXCOL 4



int *p,i,j;


p=(int *)malloc(MAXROW * MAXCOL * sizeof(int));











Q135) How can you increase the size of dynamically allocated array?

#include <alloc.h>



int *p,*t;

p=(int *)malloc(20);


t=(int *)realloc(p,40);


printf("Cannot reallocate, leaves previous allocated region unchanded");




; /* the array expanded at the same region */



free(p); /* deallocate the origianal array */

p=t; /* set p to newly allocated region */





Q136) How can you increase the size of statistically allocated array?

Ans) We cannot increase the size of statistically allocated array.

Q137) When reallocating memory if any other pointers point into the same piece of memory do you have to readjust these other pointers or do they get readjusted automatically?

Ans) If realloc() expands allocated memory at the same place then there is no need of readjustment of other pointers. However, if it allocates a new region somewhere else the programmer has to readjust the other pointers.

Q138) Which function should be used to free the memory allocated by calloc()?

Ans) free().

Q139) How much maximum can you allocate in a single call to malloc()?

Ans) 64 KB.

Q140) Can you dynamically allocate arrays in expanded memory?

Ans) Yes. Using interrupt 0x67.

Q 141) What is object file? How can you access object file?

Ans) In computer science, object file or object code is an intermediate representation of code generated by a compiler after it processes a source code file. Object files contain compact, pre-parsed code, often called binaries, that can be linked with other object files to generate a final executable or code library. An object file is mostly machine code (code directly executed by a computer's CPU). An object file format is a computer file format used for the storage of object code and related data typically produced by a compiler or assembler.

An object file contains not only the object code, but also relocation information that the linker uses to assemble multiple object files into an executable or library, program symbols (names of variables and functions), and debugging information.

Q 142) Which header file should you include if you are to develop a function which can accept variable number of arguments?

Ans) To use a function with variable number of arguments, or more precisely, a function without a set number of arguments, you would use the cstdarg header file. There are four parts needed: va_list, which stores the list of arguments, va_start, which initializes the list, va_arg, which returns the next argument in the list, and va_end, which cleans up the variable argument list. Whenever a function is declared to have an indeterminate number of arguments, in place of the last argument you should place an ellipsis (which looks like '...'), so, int a_function ( int x, ... ); would tell the compiler the function should accept however many arguments that the programmer uses, as long as it is equal to at least one, the one being the first, x. va_list is like any other variable. For example,

va_list a_list; 

va_start is a macro which accepts two arguments, a va_list and the name of the variable that directly precedes the ellipsis (...). So, in the function a_function, to initialize a_list with va_start, you would write va_start ( a_list, x );

va_arg takes a va_list and a variable type, and returns the next argument in the list in the form of whatever variable type it is told. It then moves down the list to the next argument. For example, va_arg ( a_list, double ) will return the next argument, assuming it exists, in the form of a double. The next time it is called, it will return the argument following the last returned number, if one exists.

Q 147)

i)    How do you declare An array of three pointers to chars ?
à    char *(*(*a[])())())

152) What do the functions atoi(), itoa() and gcvt() do?

Ans)  1) atoi():
à convert ASCII string to integer
    2) itoa():      

àThe itoa() function constructs a string representation of an integer

3) gcvt() :

à The gcvt() function converts a floating-point number to a string. It converts value to a null-terminated string (similar to that of the %g format of printf()) in the array pointed to by buf and returns buf. It produces ndigit significant digits (limited to an unspecified value determined by the precision of a double) in %f if possible, or %e (scientific notation) otherwise. A minus sign is included in the returned string if value is less than 0. A radix character is included in the returned string if value is not a whole number. Trailing zeros are suppressed where value is not a whole number. The radix character is determined by the current locale.

Q 154) How would you use qsort() function to sort an array of structures?

Ans)To sort an array using an arbitrary comparison function, use the qsort function. The prototype for this function is in `stdlib.h'.

Function: void qsort (void *array, size_t count, size_t size, comparison_fn_t compare)

The qsort function sorts the array array. The array contains count elements, each of which is of size size.

The compare function is used to perform the comparison on the array elements. This function is called with two pointer arguments and should return an integer less than, equal to, or greater than zero corresponding to whether its first argument is considered less than, equal to, or greater than its second argument.

Warning: If two objects compare as equal, their order after sorting is unpredictable. That is to say, the sorting is not stable. This can make a difference when the comparison considers only part of the elements. Two elements with the same sort key may differ in other respects.

If you want the effect of a stable sort, you can get this result by writing the comparison function so that, lacking other reason distinguish between two elements, it compares them by their addresses. Note that doing this may make the sorting algorithm less efficient, so do it only if necessary.

Here is a simple example of sorting an array of doubles in numerical order, using the comparison function defined above :

  double *array;
  int size;
  qsort (array, size, sizeof (double), compare_doubles);

Q 156) How would you use bsearch( ) function to search a name stored in array of pointers to string?

Ans) bsearch -binary search a sorted table

The bsearch() function searches an array of nel objects, the initial element of which is pointed to by base, for an element that matches the object pointed to by key. The size of each element in the array is specified by width.

The comparison function pointed to by compar is called with two arguments that point to the key object and to an array element, in that order.

The function must return an integer less than, equal to, or greater than 0 if the key object is considered, respectively, to be less than, to match, or to be greater than the array element. The array must consist of: all the elements that compare less than, all the elements that compare equal to, and all the elements that compare greater than the key object, in that order.

Q 157) How would you use the functions sin(), pow(), sqrt() ?