answersLogoWhite

0

📱

C++ Programming

Questions related to the C++ Computer Programming Language. This ranges all the way from K&R C to the most recent ANSI incarnations of C++, including advanced topics such as Object Oriented Design and Programming, Standard Template Library, and Exceptions. C++ has become one of the most popular languages today, and has been used to write all sort of things for nearly all of the modern operating systems and applications." It it a good compromise between speed, advanced power, and complexity.

2,546 Questions

What is c plus plus data type?

The C++ string classes are derived from the std::basic_string<T> template class, where T is a character type. The standard provides the two most common string types, std::string (std::basic_string<char>) and std::wstring (std::basic_string<wchar_t>). The former is used for ASCII strings (which includes UTF-8 strings) while the latter is used for wide-character strings, particularly UNICODE strings.

All standard library strings are represented by an array of some character type (such as char or wchar_t) however, unlike an ordinary array, the individual character elements cannot be re-ordered other by overwriting each character. If you simply need an array of characters that can be re-ordered then use a std::vector<char> or std::vector<wchar_t> rather than a string.

The standard library strings include a rich set of methods, operations and algorithms that are commonly used with strings, such as std::string::find() to locate a character within a string, std::string::substr() to extract a substring from a string, and operator+= to concatenate one string onto another. Most implementations include the short string optimisation so that short strings (up to around 14 characters or so) may be stored in local memory rather than on the heap. Many strings tend to be short so this can provide enormous performance benefits with little cost in terms of memory.

Draw a flowchart to accept 2 numbers and check if the first is divisible by the second?

Drawing flowcharts is impossible in a text-based forum. So here's the pseudocode instead:

  1. input x
  2. input y
  3. if(x%y==0) then print "x is divisible by y" else print "x is not divisible by y"

Note that line 3 divides x by y and if the remainder is 0 then x is divisible by y, otherwise it is not.

Example of encapsulation and abstraction in an object oriented programming language?

Encapsulation example:

Ink is the important component in pen but it is hiding by some other material.

Abstraction example: ATM is a good example of abstraction, we doesn't know what are all the internal processes that are going when we access it..instead we know only the inquiries, deposit, withdrawl etc...

Explain why a class might provide a set method and a get method for an instance variable?

A class might provide a set method (setter) and a get method (getter) for an instance variable in order to encapsulate the internal implementation of the class, and to isolate that implementation from the public interface of the class.

Even if the setter and getter does no more than directly set and get the instance variable, the public interface should use that paradigm in order to allow for possible future alteration of the implementation, while minimizing the impact of doing so.

Proper OOD/P (Object Oriented Design/Programming) should always make the implementation be private, even for derived classes. This reduces error, and reduces "lazy" coding techniques.

How do you make a function repeat itself in C plus plus?

There are three ways to do repetitions in C as far as I know. The first is to use recursion (a function which calls itself) the second being a for loop and the third being a while loop, though both of these are basically the same thing. Here's a demonstration of using these three methods to compute the x raised to the power of y: (note this isn't the most efficient way of calculating the power of a number but it's good enough for an example)

//Recursion:

int pow(int base, int pwr){

if(pwr == 0){

return 1;

}else{

return base * pow(base, pwr - 1);

}

}

//For loop

int pow(int base, int pwr){

int i;

int result = 1;

//The for loop initialises i to the value of pwr, then

//runs the loop, subtracting 1 from i each time until

//i fails the test (i > 0) at which point the loop finishes

for(i = pwr; i > 0; i--){

result *= base

}

return result;

}

//While loop

int pow(int base, int pwr){

int result = 1;

while(pwr > 0){

result *= base;

pwr--;

}

return result;

}

How do you instantiate an object in OOP?

In most OOP languages, you use the "new" keyword to indicate that you wish to create an object of a given class. Often, that construct will look as follows:

PlayerCharacter pc = new PlayerCharacter("Jane Doe");

The first PlayerCharacter is the "data type" for the variable "pc". Equals ("=") assigns the right-hand value to the left-hand value (pc). The new keyword indicates that you wish to allocate memory for an object and call a constructor. The second PlayerCharacter calls the constructor for the PlayerCharacter class, which expects a single string for the player character's name (presumably).

Disadvantages of template in c plus plus?

When used correctly and for the purpose intended there are no disadvantages to templates. Templates are type-safe, can be debugged by the compiler and make it easier to write functions and classes that operate upon a type without the need to write duplicate code by hand. If you're using templates for any other purpose then there will obviously be disadvantages. However, when you consider the alternatives, macros are disadvantageous because they are not type-safe, cannot be debugged by the compiler and are always inline expanded (which is not always a good thing), while coding by hand is disadvantageous because it introduces duplicate code and increases the maintenance cost of that code. All three methods have their uses, but when used incorrectly you will always find disadvantages. That is not the fault of the methods themselves, that is the fault of the programmer.

What are the parts of an array?

Its type, name and number of elements.

char example[12]; // a char array, named 'example' with 12 elements.

The name is also a reference to the array itself, referring to the first element in the array (e.g., example == &example[0]).

When is memory allocated when declaring an array in C plus plus?

It depends how the array is declared (fixed size or variable size) and where it is declared (global scope or local scope).

If the array is declared in global scope (outside a function) and is fixed size, it will be allocated in static memory. If it is variable size, the pointer is stored in static memory while the array itself is allocated on the heap. The pointer in static memory points to the start address of the array in heap memory.

If the array is declared in local scope (inside a function) and is fixed size, it will be allocated on the stack in whichever thread the function was called. If it is variable size, the local pointer is stored on the stack while the array is allocated on the heap. The pointer will fall from scope when the function returns so the array must not be allowed to outlive the function in which the pointer is declared. If the array must outlive the function that allocates the array, the pointer must be declared at a higher scope in the call stack and must be passed by reference to or returned by value from the function that allocates the array.

If you provide your own memory manager, however, an array may be allocated wherever the memory manager's memory pool is allocated, be it in static memory, the stack or the heap. A memory manager essentially allocates an array of bytes which you can then utilise as you see fit (the array of bytes will be allocated as per the previous description for arrays in general).

Importance of virtual functions?

Private virtual functions are useful when you expect a particular method to be overridden, but do not wish the override to be called from outside of the base class. That is, the base class implementation and its overrides remain private to the base class.


Private virtual methods are particularly useful in implementing template method patterns, where certain algorithmic steps need to be deferred to subclasses, but where those steps need not be exposed to those subclasses. In many cases the private virtual methods will be declared pure-virtual, thus rendering the base class an abstract base class.


What is a constructor initialization list?

The constructor initialisation list is the most efficient method of initialising class members, including primitive members. You use it always and without exception to ensure efficient construction.

Consider the following:

class foo

{

int m_data;

public:

foo(int data=0){ m_data=data; }

foo(const foo& f){ m_data=f.m_data; }

};

This class employs inefficient construction technique by initialising the member variables in the constructor bodies rather than the initialisation list. In other words, m_data is instantiated and initialised in two stages instead of one. It is not unlike the following two stage initialisation:

int m_data;

m_data =0;

A more efficient way of writing these lines is to initialise at the point of instantiation using a compound statement:

int m_data=0;

The same applies to class construction. By using the initialisation list, member variables are initialised at the point of instantiation, as per the following:

class foo

{

int m_data;

public:

foo(int data=0):m_data(data) {}

foo(const foo& f):m_data(f.m_data) {}

};

You will note that primitive members use object-oriented syntax in the initialisation list. This is not merely sugar-coating -- it applies to all members, including base classes. This makes it possible to invoke specific base class constructors, rather than the default constructor that would be implicitly invoked (or the base class copy constructor in the case of a derived class copy constructor).

Consider the following:

class base

{

int m_data;

public:

base(int data=0):m_data(data) {}

base(const base& b):m_data(b.m_data) {}

};

class derived : public base

{

public:

derived(int data=0):base(data) {}

derived(const derived& d):base(d) {}

};

Note how the derived class default constructor invokes the base class default constructor, but passes the data argument to it. Had you not used the initialisation list you'd have to construct base, then derived, and then initialise the base class member via a setter. Clearly the initialisation list is more efficient because the base class can be initialised before derived is even instantiated, which cannot happen until the base class is fully-instantiated.

Note also that the copy constructor specifically invokes the base class copy constructor. Although the argument, d, is not a base class, it is a type of base class, thus there is no need to upcast the argument.

Ultimately, it can be seen that the constructor bodies are largely redundant. You still need a constructor body, even an empty one, but most of the time you will use the body for debug trace code. There will be times, however, where the class initialisation list cannot fully initialise a member because one or more arguments require more complex processing (such as calling a complex setter). In this case, you must use the constructor body. However, you must still perform as much initialisation as is possible via the initialisation list to ensure the most efficient construction method. Only those members that require additional processing need not be initialised, but it costs nothing to initialise them to an arbitrary or default value.

The initialisation list is vital in the case of the copy constructor, as passing an object to a function by value will automatically invoke the copy constructor. If any member variables are embedded objects, or the object is derived from one or more base classes, then their copy constructors will be invoked as well. Therefore it pays to make construction as efficient as possible when copying objects. However, the same applies to any constructor. The more efficient the constructor performs, the better your programs will perform, especially in complex hierarchies where objects may be deeply embedded within other objects that are themselves embedded.

What is the difference between C and java?

You're comparing apples and oranges. C is a procedural language. You can, using structures and functions to access those structures do everything you can in Java. In fact, if you look into GObject, the object oriented method of programming in GTK (the Linux toolkit) people do this all the time. In fact they have pretty much implemented C++ manually using a programming style and macros.

C++ and Java have a great deal more in common. From a language perspective, they are nearly identical. Java is arguably cleaner as it doesn't depend on forward declaration and therefore all functions are coded directly within the class definitions themselves. C++ is arguably more powerful as you have direct access to the hardware of the system and it's also possible to write code in such a way that it is guaranteed to be compiled an optimized in a specific manor.

For application development, Java is often faster (performance and in the time it takes to get the job done). For system level development, C++ is almost always a clear winner. I won't detail it as it's far beyond the scope of the question.

There are two key differences between Java and C++ to a programmer.

1) Java is a garbage collected language

This means you can allocate memory and just forget about it when you're done. Some people say this leads to ugly code and quite frankly, I agree. Bad programmers can be REALLY bad programmers in Java and get away with it. C++ a C++ program will tend to crash your machine if you write it badly. The selling point of garbage collection is performance. It allows the runtime system of the language to clean up when there's time to do it instead of having to clean up during time critical moments. In C++ this type of behavior has to be coded manually and requires a great deal of strategic planning to accomplish.

2) Java has a "good" defined set of standard class libraries.

C++ has libraries also, but only a small percentage of programmers use them because many of us (me included) consider them to be a plague on the language. They're VERY over-engineered and can be very hard to debug. Java's libraries are a lot cleaner even if they have serious inconsistencies (this may spur a political debate, but I offer my opinion and the arguments I've heard from others).

Neither language is particularly good. Neither runtime is particularly modern. There are newer technologies such as C#/.NET and others which have arguably learn from C++ and Java and built upon what was learned.

If you're learning to program, I recommend using C++ with Qt (from Nokia) as it gives you almost the best of both worlds. If you're using one and looking to switch to the other. It should be a smooth transition, the languages are basically the same.

If you're asking about internal data structure. The two languages aren't comparable as Java doesn't have a strict internal structure definition and therefore can't be compared.

P.S. - For a bonus, Java's best feature is relocatable memory. Because it forces you to never use memory locations directly (pointers), so the java virtual machine can relocate your memory in order to make room for larger allocations that otherwise wouldn't fit without paging or asking the OS for more RAM. This can make your applications more efficient as virtual memory paging is far more expensive than simply defragging the memory occasionally.

What happens if recursion function is declared inline?

An inline function replaces the call to the function by the body of the function, thus reducing the overhead of saving the context in stack. This is good for functions which are small in size and called occasionally. A recursive function calls an instance of itself and thus can be a deeply nested. Different compilers handle this differently. Some will inline it up to a certain depth and then call a non-inlined instance for further recursion; others will not inline the function at all and generate a normal function call.

How do you get free borland c plus plus software?

There are many vendors of C++ compilers. Your choice depends on what platform you use, and whether or not you want paid support. Two compilers (remember, there are many) are GCC, at gcc.gnu.org, and Visual Studio, at www.microsoft.com/vstudio. Be sure to review the requirements, cost, and license details before you choose.

How implemention of election algorithm in c plus plus language?

#include<stdio.h>

#include<conio.h>

#include<process.h>

struct proc

{

int live;

int identifier;

}process[10];

int n,cordinator=1;

/******************* DISPLAY PROCESSES **********************/

void display()

{

int i;

printf("\n PROCESSES ARE\n\n");

printf("Processes ");

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

{

printf("P%d\t",i);

}

printf("\nlive ");

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

{

printf("%d\t",process[i].live);

}

printf("\nidentifier ");

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

{

printf("%d\t",process[i].identifier);

}

}

/************ BULLY ALGORITHM ****************************/

void bully()

{

int ch,c,id,i=0,cordinator,init,max=-99;

cordinator=i;

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

{

if(process[cordinator].identifier<process[i].identifier&& process[i].live==1)

cordinator=i;

}

printf("\n\n CURRENT CO-ORDINATOR IS=P%d",cordinator);

while(ch!=4)

{

printf("\n\n\n *** BULLY ALGORITHM ***");

printf("\n1.Crash a Process\n2.Activate Process\n3.Display\n4.Exit");

printf("\nENTER UR CHOICE");

scanf("%d",&ch);

switch(ch)

{

case 1:printf("\n Enter the process id to crash");

scanf("%d",&id);

if(process[id].live==0)

{

printf("\n Already crashed process");

}

else

{

process[id].live=0;

printf("\n process P%d is crashed",id);

if(id==cordinator)

{ while(1)

{

printf("\n Enter process id who intiates election");

scanf("%d",&init);

if(process[init].live==0)

{

printf("\n the selected process is crashed");

}

else

{

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

{

if(i!=init&& process[i].identifier>process[init].identifier)

printf("\n Election MSG sent from %d to %d",init,i);

}

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

{

if(i!=init)

{

if(process[i].identifier>process[init].identifier&&process[i].live!=0)

{

printf("\n OK from %d to %d",i,init);

}

}

}

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

{

if(max<process[i].identifier && process[i].live!=0)

{

cordinator=i;

max=process[i].identifier;

}

}

printf("\n\n NEW CO-ORDINATOR IS=P%d",cordinator);

break;

}

}

}

}

break;

case 2:printf("\n Enter process id to activate");

scanf("%d",&id);

if(process[id].live==1)

{

printf("\n Process %d is already active",id);

}

else

{

process[id].live=1;

printf("\n Process %d activated",id);

}

if(process[id].identifier>process[cordinator].identifier)

{cordinator=id;

printf("\n NEW CO-ORDINATOR IS=P%d\n\n",id);

}

break;

case 3:display();

break;

case 4:break;

}

}

}

/************ RING ALGORITHM ****************************/

void ring()

{

int ch,c,id,i=0,init,max=-99,last;

// cordinator=i;

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

{

if(process[cordinator].identifier<process[i].identifier&&process[i].live==1)

cordinator=i;

}

printf("\n\n CURRENT CO-ORDINATOR IS=P%d",cordinator);

while(ch!=4)

{

printf("\n\n\n *** RING ALGORITHM ***");

printf("\n1.Crash a Process\n2.Activate Process\n3.Display\n4.Exit");

printf("\nENTER UR CHOICE");

scanf("%d",&ch);

switch(ch)

{

case 1:printf("\n Enter the process id to crash");

scanf("%d",&id);

if(process[id].live==0)

{

printf("\n Already crashed process");

}

else

{

process[id].live=0;

printf("\n process P%d is crashed",id);

if(id==cordinator)

{ while(1)

{

printf("\n Enter process id who intiates election");

scanf("%d",&init);

if(process[init].live==0)

{

printf("\n the selected process is crashed");

}

else

{ last=init;

printf("\nElection MSG sent from =%d",last);

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

{

if(i!=init)

printf(" ->%d",i);

}

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

{

if(i!=init)

printf("->%d",i);

last=i;

}

/*

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

{

if(i!=init)

{

if(process[i].identifier>process[init].identifier&&process[i].live!=0)

{

printf("\n OK from %d to %d",i,init);

}

}

} */

// max=process[init].identifier;

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

{

if(max<process[i].identifier && process[i].live==1)

{

cordinator=i;

max=process[i].identifier;

}

}

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

{

if(max<process[i].identifier && process[i].live==1)

{

cordinator=i;

max=process[i].identifier;

}

}

printf("\n\n NEW CO-ORDINATOR IS=P%d",cordinator);

break;

}

}

}

}

break;

case 2:printf("\n Enter process id to activate");

scanf("%d",&id);

if(process[id].live==1)

{

printf("\n Process %d is already active",id);

}

else

{

process[id].live=1;

printf("\n Process %d activated",id);

if(process[id].identifier>process[cordinator].identifier)

{

printf("\n NEW CO-ORDINATOR IS=P%d\n\n",id);

cordinator=id;

}

}

break;

case 3:display();

break;

case 4:break;

}

}

}

void main()

{

int ch,i,c;

clrscr();

printf("\n ENTER NO. OF PROCESSES");

scanf("%d",&n);

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

{

printf("\nEnter P%d process live or not(0/1)",i);

scanf("%d",&process[i].live);

printf("\nEnter P%d process identifier",i);

scanf("%d",&process[i].identifier);

}

display();

while(1)

{

printf("\n\n\n**** ELECTION ALGORITHM ****");

printf("\n1.BULLY ALGORITHM\n2.RING ALGORITHM\n3.EXIT");

printf("\n\n ENTER UR CHOICE");

scanf("%d",&ch);

switch(ch)

{

case 1:bully();

break;

case 2: ring();

break;

case 3:exit(0);

}

}

}

What are callback functions?

In computer science, a callback is executable code that is passed as an argument to other code. It allows a low level software layer to call a function occurring in a higher level layer. Usually the higher level code first calls a function within the lower level code passing to it a pointer or handle to another function. Then the lower level function in the course of executing may call the passed-in function any number of times to perform some subtask. Another option is that the lower level function registers the passed-in function as a handler that is to be called asynchronously by the lower level at a later time in reaction to something. A callback can be used as a simpler alternative to polymorphism and generic programming, in that the exact behavior of a function can be dynamically determined by passing different (yet compatible) function pointers or handles to the lower level function. This can be a very powerful technique for code reuse.

What is a block in c plus plus?

Assuming you mean a code block, a group of simple statements enclosed in braces {} is regarded as a code block. In other words, a compound statement. Braces are not required around simple statements except when the statement is the body of a function (where braces are mandatory).

What are the advantage of function prototype?

It allows the compiler to verify that the number and types of the functions parameters are correct when the function is actually called.

If the function were called with the wrong number or type of parameters, and no function prototype were supplied, the error would not be discovered until the program was actually run.

How ploymorphism and inheritance is different from that in Java and c plus plus?

C++ allows multiple inheritance while Java does not. In my opinion, multiple inheritance is not useful because it can get very confusing very quick.

For polymorphism, C++ does early binding by default, while Java does late binding by default. Late binding is more useful than early binding.

Structure in c plus plus?

Structures are the same as classes in C++. The only difference is that structure members are public by default while class members are private by default, but both define a class of object and both are initialised via a class constructor initialisation list.

struct my_object

{

my_object(const int data): m_data(data) {}

private:

int m_data;

};

The above struct is no different to the following class:

class my_object

{

int m_data;

public:

my_object(const int data): m_data(data) {}

};

Write a c plus plus program to demonstrate call by value and call by reference?

#include<iostream>

void byval(int y)

{

std::cout<<"byval: &y="<<&y<<std::endl;

}

void byref(int& z)

{

std::cout<<"byref: &z="<<&z<<std::endl;

}

int main()

{

int x=42;

std::cout<<"main : &x="<<&x<<std::endl;

byval(x);

byref(x);

return(0);

}

Example output:

main : &x=001DF800

byval: &y=001DF72C

byref: &z=001DF800

When you pass by value, the y argument has a different memory address to that of x. In other words, y is a copy of x (you pass the value of x, not x itself). Thus any changes made to y will have no affect upon x. Often this is desirable, but note that when passing a complex object by value, you will automatically invoke the object's copy constructor, which is often unnecessary. Pass by value should only be used when the function needs to modify the argument's value, but without affecting the argument that was passed.

When you pass by reference, the z argument has the same address as x. Thus z refers to x. In other words, z is an alias, an alternate name, for x, thus any changes made to the value of z will also change the value of x, since they are one and the same variable. If the function does not actually need to alter the value of the reference, then the reference should be declared constant. This assures the caller that the object's immutable members will not be altered by the function.

Note that you can also achieve pass by reference by passing a pointer to the variable. Pointers are always passed by value, thus the pointer will actually be a copy of the pointer you pass, but both pointers will still refer to the same memory address, thus the net effect is a pass by reference. However, if a pointer is guaranteed to be non-NULL, then it is more efficient to pass the address being pointed at by reference, since references can never be NULL (a NULL reference will invalidate your program).

To pass a pointer by reference, you need to add an extra level of indirection. Thus when passing a pointer to an int (int*), you need to pass a pointer to a pointer to int instead (int**). The pointer to pointer is passed by value, but the pointer to int is effectively passed by reference, thus allowing you to change the value of both the pointer and also what it is pointing at (unless one, the other, or both, are declared const).

A multithreaded program that generates the Fibonacci series using Pthreads?

#include<stdio.h>

#include<time.h>

#include<pthread.h>

#include<stdlib.h>

#include<sys/types.h> /* need to calculate which I will implement later */

void *fibr(void *n);

void *fibr_1(void *k);

signed long long int fibonacci(signed long long int);

int main(){

clock_t begin, end;

double time_spent;

pthread_t tid,tid1;

int result,result1;

signed long long int n=6;

signed long long int m=7;

result=pthread_create(&tid,NULL,fibr,&n);

if(result){

perror("pthread_create");

return 1;

}

result1=pthread_create(&tid1,NULL,fibr,&m);

if(result1){

perror("pthread_create");

return 1;

}

if(pthread_join(tid,NULL)){

perror("pthread_join");

return 1;

}

if(pthread_join(tid1,NULL)){

perror("pthread_join");

return 1;

}

printf("Fib value=%lld\n",n+m);

pthread_exit(NULL);

}

void *fibr(void *n){

signed long long int *y=n;

signed long long int x=*y;

pthread_t tid2,tid3;

signed long long int i,j;

/* How do I assign values to i , j in order to

achieve the level viz fib(n-2)....fib(n-4) */

if(pthread_create(&tid2,NULL,fibr_1,&i))

{

perror("pthread_create");

}

if(pthread_create(&tid3,NULL,fibr_1,&j))

{

perror("pthread_create");

}

if(pthread_join(tid2,NULL))

{

perror("pthread_join");

}

if(pthread_join(tid3,NULL))

{

perror("pthread_join");

}

/* How to return the values of i, j combined with *y . if I do *y+i+j, the result

is not coming correctly */

*y=fibonacci(x);

return NULL;

}

void *fibr_1(void *k){

long long int *a=k;

long long int b=*a;

*a=fibonacci(b);

return NULL;

}

signed long long int fibonacci(signed long long int x){

if((x==0)(x==1))

return x;

return fibonacci(x-1)+fibonacci(x-2);

}

What is dereferencing pointer?

They're related but not totally comparable.

A pointer is an address in memory where a variable is located.

An array is a conceptual data representation consisting of a list of more than one item of a particular scalar type (int, float, char, structure, etc.) where each element is accessed by its index. The index can be thought of as a counter or enumerator telling you how many elements you have to skip over to get to the one you're interested in. Here's where addresses come in ... the location of a particular element in memory is offset from the so-called base address (i.e. the address of the starting element) by the value

(sizeof(one element) * index #)

The C compiler is smart enough to take the sizeof() into account when you do pointer arithmetic, so you can find the address of the i-th element as (address of base) + i, rather than having to do the multiplication explicitly.

The idea of element address as offset also accounts for C's use of zero-relative array definitions. Since the first element is offset by 0 positions from the first element its index in C is 0, not 1. The second (ordinal) element is offset from the first by 1 position so its index is 1, and so on.

What is the use of private constructor in c plus plus?

Private construction prevents objects from the class from being instantiated other than via a static member function of the class, a friend function or a friend class.

What are advantages and disadvantages of priority queue?

In CQ we utilize memory efficiently. because in queue when we delete any

element only front increment by 1, but that position is not used later. so when

we perform more add and delete operation, memory wastage increase. But in CQ

memory is utilized, if we delete any element that position is used later,

because it is circular.