Search
  • 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.

Example:

main()

{

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.

Advantages:

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?

Ans)

Array

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 ?

Ans)

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?

Ans)

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

3>Global

Storage Allocation – Memory

Scope –Global

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

Default Initial value – Zero

4>Local

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] ?

*(*(*(*(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?

Ans)

                                     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

Example

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?

Ans)

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

OR

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?

Ans)

The ‘&’ operator

The ‘OR’ operator

.

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

Ans)

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;

clrscr();

gets(s1);

gets(s2);

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

printf("Strings not equals");

else

{

for(i=0;i<strlen(s1);i++)

if(*(s1+i)!=*(s2+i))

break;

if(i==strlen(s1))

printf("Strings are equals");

else

printf("Strings are not equals");

}

getch();

}

Q125) Write a program to concatenate two strings.

Ans) #include<stdio.h>

void main()

{

char *s1,*s2;

int l,i;

clrscr();

gets(s1);

gets(s2);

l=strlen(s1);

for(i=0;i<strlen(s2);i++)

*(s1+l+i)=*(s2+i);

puts(s1);

getch();

}


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

#include <stdio.h>

void main()

{

int i,j;

clrscr();

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

i=i+j;

j=i-j;

i=i-j;

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

getch();

}


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;

clrscr();

printf("Enter Your string : ");

gets(str);

while(str[j]!='\0')

j++;

j--;

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

while(str[j])

printf("%c",str[j--]);

getch();

}

Palindrome

#include<stdio.h>

void main()

{

char *s;

int l,i,j;

clrscr();

gets(s);

l=strlen(s);

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

{

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

{

printf("Not Palindrom");

break;

}

}

if(i==(l-1))

printf("Palindrom");

getch();

}

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;

clrscr();

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

scanf("%d",&n);

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

for(i=0;i<n;i++)

{

j=k;

k=fib;

fib=j+k;

printf("\n%d",fib);

}

getch();

}

Q129) Write a program to generate the Fibonacci Series.

#include <stdio.h>

#include <conio.h>

void main()

{

long i,n,fact=1;

clrscr();

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

scanf("%ld",&n);

for(i=1;i<=n;i++)

fact*=i;

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

getch();

}

Q130) Write a program which employs Recursion.

#include <stdio.h>

void main()

{

int n,fact;

clrscr();

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

scanf("%d",&n);

fact=rec_fact(n);

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

getch();

}

rec_fact(int x)

{

int f;

if(x==1)

return 1;

else

f = x * rec_fact(x-1);

return f;

}

Q131) Write a program which uses Command Line Arguments.

#include<stdio.h>

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

{

int i;

clrscr();

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

for(i=0;i<argc;i++)

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

getch();

}

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

#include<stdio.h>

void main()

{

char *s1,*s2;

clrscr();

gets(s1);

gets(s2);

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

strcpy(s1,s2);

printf("\n\n%s",s1);

getch();

}

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?

One-Dimensional

#include <alloc.h>

#define MAX 10

main()

{

int *p,i;

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

for(i=0;i<MAX;i++)

{

p[i]=i;

printf("\n%d",p[i]);

}

}

Two-Dimensional

#include <alloc.h>

#define MAXROW 3

#define MAXCOL 4

main()

{

int *p,i,j;

clrscr();

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

for(i=0;i<MAXROW;i++)

{

for(j=0;j<MAXCOL;j++)

{

p[i*MAXCOL+j]=i;

printf("\n%d",p[i*MAXCOL+j]);

}

printf("\n");

}

}

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

#include <alloc.h>

main()

{

int *p,*t;

p=(int *)malloc(20);

t=p;

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

if(t==NULL)

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

else

{

if(p==t)

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

else

{

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() ?

Ans) sin ( ) :

Returns the sine of an angle.

                                     Sin(number)

The Sin function takes an angle and returns the ratio of two sides of a right triangle. The ratio is the length of the side opposite the angle divided by the length of the hypotenuse. The result lies in the range -1 to 1.

To convert degrees to radians, multiply degrees by pi/180. To convert radians to degrees, multiply radians by 180/pi.

 
ii)   pow():

Usage:

   #include <math.h>
    z = pow( x, y );

Where:

double x, y, z;

Description:

"pow" returns "x" to the power "y". If "x" and "y" are both zero, or if "x" is non-positive and "y" is not an integer, "pow" return -HUGE_VAL and sets "errno" to EDOM. If the answer would cause an overflow, "pow" returns +HUGE_VAL.

iii) sqrt ( ) :

Usage:

  #include <math.h>
  y = sqrt();

Where:

double x, y;

Description:

"sqrt" returns the square root of "x". If "x" is negative, "sqrt" returns zero and sets "errno" to EDOM.

Q 158) How would you use the functions memcpy(), memset(), memmove()?

Ans) memcpy( ) :

memcpy copies data between two memory locations. This function will copy the supplied number of bytes stored at the location pointed to by 's2' to the location pointed to by 's1'.

Prototype :

  Library:   string.h
 
  Prototype: char memcpy(void *s1, void *s2, int num);
 
    Syntax:
               float data1;
               char  data2[64];
               
               memcpy(data1, data2, sizeof(data2));

1) memset( ) :

SYNOPSIS

 
 
#include <string.h>
 
void *memset(void *s, int c, size_t n);
 

DESCRIPTION

The memset() function copies c (converted to an unsigned char) into each of the first n bytes of the object pointed to by s.

 

2) memmove ( ) :

The memmove() function shall copy n bytes from the object pointed to by s2 into the object pointed to by s1. Copying takes place as if the n bytes from the object pointed to by s2 are first copied into a temporary array of n bytes that does not overlap the objects pointed to by s1 and s2, and then the n bytes from the temporary array are copied into the object pointed to by s1.

Q 159) How would you use the functions fseek(), freed(), fwrite() and ftell()?

Ans) fseek( ) :

SYNOPSIS

#include <stdio.h> int fseek(FILE *stream, long offset, int whence);

int fseeko(FILE *stream, off_t offset, int whence);

The fseek() function shall set the file-position indicator for the stream pointed to by stream. If a read or write error occurs, the error indicator for the stream shall be set and fseek() fails.

The new position, measured in bytes from the beginning of the file, shall be obtained by adding offset to the position specified by whence. The specified point is the beginning of the file for SEEK_SET, the current value of the file-position indicator for SEEK_CUR, or end-of-file for SEEK_END.

If the stream is to be used with wide-character input/output functions, the application shall ensure that offset is either 0 or a value returned by an earlier call to ftell() on the same stream and whence is SEEK_SET.

A successful call to fseek() shall clear the end-of-file indicator for the stream and undo any effects of ungetc() and ungetwc() on the same stream. After an fseek() call, the next operation on an update stream may be either input or output.

1) fread( ) :

SYNOPSIS

#include <stdio.h> size_t fread(void *restrict ptr, size_t size, size_t nitems, FILE *restrict stream);

The fread() function shall read into the array pointed to by ptr up to nitems elements whose size is specified by size in bytes, from the stream pointed to by stream. For each object, size calls shall be made to the fgetc() function and the results stored, in the order read, in an array of unsigned char exactly overlaying the object. The file position indicator for the stream (if defined) shall be advanced by the number of bytes successfully read. If an error occurs, the resulting value of the file position indicator for the stream is unspecified. If a partial element is read, its value is unspecified.

2) fwrite ( ) :

SYNOPSIS

#include <stdio.h> size_t fwrite(const void *restrict ptr, size_t size, size_t nitems, FILE *restrict stream);

The fwrite() function shall write, from the array pointed to by ptr, up to nitems elements whose size is specified by size, to the stream pointed to by stream. For each object, size calls shall be made to the fputc() function, taking the values (in order) from an array of unsigned char exactly overlaying the object. The file-position indicator for the stream (if defined) shall be advanced by the number of bytes successfully written. If an error occurs, the resulting value of the file-position indicator for the stream is unspecified.

3) ftell( ) :

SYNOPSIS

#include <stdio.h> long ftell(FILE *stream);

The ftell() function shall obtain the current value of the file-position indicator for the stream pointed to by stream

Q161). what is diffrence between the function randomize( ) and random( ) ?

Ans) randomize ( ) Initialises random number generation with a random value based on time and random ( ) generates random numbers .

Q164) What is diffrence between the functions memmove( ) and memcpy( )?

Ans) memmove( ) copies a specific number of characters from one buffer to another and memcpy( ) copies a specified number of characters from one buffer to another.

Q167) What is an object?

Ans)Objects are the basic run-time entities in an object-oriented system.

Q168) What is diffrence between an object and a class?

Ans) Objects are variables of the type class and a class is the collection of objects of similar type.

Q169)What is diffrence between class and a structure?

Ans) Classes are used to hold both data and functions and structures are exclusively hold data .

Q170) What is public , protected ,private?

Ans) public members can be accessed from outside the class also, protected is accessible by the member functions within its class and any class immidiately derived from it, private can be accessed only from within the class.

Q171)What are virtual functions?

Ans) virtual functions are used to call the functions of diffrent class.virtual function is used to achive polymorphism.

Q172)What is friend function?

Ans) Friend functions are useful to access private data of a class from a non-member function. and to increase the versatility of overloaded operations.

Q173)What is scope resolution operator?

Ans) This operator allows access to global version of a variable.

Q174)What do you mean by inheritance?

Ans)Inheritance is the process by which object of one class aquire the properties of object of another class.

Q175)What is abstraction?

Ans) abstraction refers to the act of representing essential features without including the background details or explanations.

Q176) What is polymorphism ? Explain with an example.

Ans) polymorphism means the ability to take more than one form.

example: consider the operation of addition , for two numbers the operation will generate sum and for two strings operation will produse third string by concatenation.

Q177) What is encapsulation?

Ans) The wrapping up of data and functions into a single unit (called class) is known as encapsulation.

Q179) What is function overloading and operator overloading ?

Ans) Using a single function name to perform diffrent types of tasks is known as function overloading and the process of making an operator to exhibit diffrent behaviour in diffrent instances is known as operator overloading.

Q180)What is virtual class and friend class?

A.Virtual class takes necessary care to see only one copy of the class is inherited , regardless of how many inheritance paths exist between virtual class and a derived class. and friend class is used to make all the member functions of a class accessible from any class.

Q181)What do you mean by inline function.

Ans)An inline function is a function that is expanded in line when it is invoked.That is ,

compiler replaces the function call with the corresponding function code.

Q182)What do you mean by public,private,protected & friendly ?

ANS)The clas body contains declarartion of variable & functions.These functions

& variable are collectively called class memebers.

The class members that have been declared as public can be accessed from

outside the class also.