What is the advantage of doubly linked list over Doubly linked list?
A doubly linked list can be traversed in both directions (forward and backward). A singly linked list can only be traversed in one direction.
A node on a doubly linked list may be deleted with little trouble, since we have pointers to the previous and next nodes. A node on a singly linked list cannot be removed unless we have the pointer to its predecessor. On the flip side however, a doubly linked list needs more operations while inserting or deleting and it needs more space (to store the extra pointer).
What is the difference between stack and array?
Briefly, there are two main differences between an array and a stack. Firstly, an array can be multi-dimensional, while a stack is strictly one-dimensional. Secondly, an array allows direct access to any of its elements, whereas with a stack, only the 'top' element is directly accessible; to access other elements of a stack, you must go through them in order, until you get to the one you want. I hope this answered your question.
OK?
What are disadvantages of a linked list over an array?
A linked list is better bcoz:
1. A linked list can be grown to any size whereas a statically allocated array is of a fixed size and hence can cause problems if you try to insert beyond that.
2. Deletion of elements is a problem in arrays. You either have to move all the elements following the deleted element forward which is a waste of time or you have to place a sentinel indicating that the element in that position is deleted which causes a waste of space.
On the flip side, arrays are easier to handle because their memory allocation is done once and for all(atleast till you need more space and have to reallocate) and because there is no hassle with pointers.
How is a multi-dimensional array defined in terms of a pointer?
Yes. More specifically, they can be used to represent a dynamic multi-dimensional array.
As most people know, for a one-dimensional dynamic array, you simply need a pointer to the first element in the array, where each element contains an object of the same type as the pointer. The pointer can be passed around functions just as if it were a static array, the only difference being the requirement to pass the upper bound of the array as well as the array itself.
For a two-dimensional array, you need a pointer-to-pointer which points to the first element of a one-dimensional pointer array, where each pointer in that array points to a one-dimensional array of objects. The pointer-to-pointer must be the same type as the pointers and the objects.
For a three-dimensional array you need a pointer-to-pointer-to-pointer. And so on. Each additional dimension simply adds a new level of indirection, and a new level of one-dimensional pointer arrays.
Of course multi-dimensional arrays are only useful if every dimension is fully utilised and doesn't require too much in the way of resizing. If that is not the case, then you may get more efficient memory consumption from a vector of vectors (of vectors), which allows dynamic resizing at every level without having to copy existing elements. The downside is you lose the random access provided by the array.
What is the c program to find the octal equivalent of an integer?
void Decimal_to_Octal()
{
int n,r[10],i;
cout<<"Enter a number to find it's octal equivalent";
cin>>n;
cout<<"The octal equivalent of "<
{
r[i]=n%8;
n=n/8;
}
i--;
for(;i>=0;i--)
cout<
Value of jc higgens model 50 30-6?
I have a JC Higgins model 60 in pristine condition, and it it worth, supposedly, around $150. But, it is a GREAT gun, and to me, worth a whole lot more. It was the first gas-operated semi-auto shotgun on the market, and kicks a lot less than a newer gas-operated Remington semi-auto than I've got. I'll never part with it. Al In good to excellent con . 125 to 200 dollars these guns came out in 1956 and when they first were introduced they were one of the most advanced semi autos out there they are still nice guns and have some value
C code to sort array of integers in descending order?
#include
#include
#include
#include
void main()
{
clrscr();
int n,i,term,j;
int x[100];
printf("/nEnter no. of terms (N) " );
scanf("%d",&n);
for(i=0;i
{
printf("n/Enter %d element",i+1);
scanf("%d", &x[i]);
}
printf("/given arrary is");
for(i=0;i
printf("/n %d",x[i]);
for(i=0;i
for(j=i+1;j
if(x[i]
{
term = x[i];
x[i] = x[j];
x[j] = term;
}
printf("/nSorted array is given below");
for(i=0;i
printf("/n%d",x[i]);
getch();
}
A pointer is a programming tool that allows a value to be referenced. All data is allocated in memory and has a certain address attached to them. When you use a pointer, you are taking a value from an address called the reference. The original data is called the reference, and taking that value using a pointer is called dereferencing.
Example using Objective-C:
int anInt = 42; (anInt is stored in memory with the value of 42)
int *anIntPointer; (this is new datatype that wants to point to a certain address)
*anIntPointer = &anInt; (you are taking the pointer and dereferencing it to anInt. anytime you have a pointer [in this case denoted with an asterisk "*"], the reference will be noted with an ampersand "&")
Now there are also pointers to objects and structs that use an entirely different method, but same idea, the pointer grabs a referenced data value. This is especially valuable for referencing structures without having to reference every single member variable.
What are the benefits of using functions?
A static function in class scope (within a class) can access only static class members (for all instances of the class). A static function in file scope (not within a class) is visible only to code within that compilation unit, i.e. it cannot be linked from file to file.
What are the function of an interpreter and a compiler?
An interpreter is a computer program that translates a high-level computer program into machine code while it is executing. As a result of this runtime interpretation, an interpreted program executes more slowly and consumes more resources than an equivalent standalone machine code executable would. To create standalone machine executables from high-level language sources you require a compiler and linker. Alternatively, you can write the program in low-level assembly language and use an assembler to create the executable, however high-level languages are easier to work with and can more easily produce executable code that is as efficient if not more efficient than is possible with low-level assembly language.
Which one is better between structure and union?
Sub:- C programming class:- f.y.b.sc(cs) name:-sintu mehta Union:- all member of the union share is storage in the computer memory 2. Only one member can be active at a time 3. Only first union variable can be initialized 4. Conservation the memoy
How can you create a headerfile in a c?
Create the header file as a .h file in the same way you create a source file, .c and place it in the same directory as the .c files. To incorporate it, use the...
#include "my_header_file.h"
... directive. Note that there are double quotes instead of greater/less signs. This tells the compiler to look first in the source directory.
Why do you use of operator overloading in c?
Overloading, Overriding, Polymorphism, Information Hiding, Inheritance all these are CONCEPTS of C++ and Java. An Object Oriented Language and not of C language. Thats why Bjarne Stroustrup came up with C++ ...
int sumEvens = 0;
int sumOdds = 0;
int i;
for(i = 0; i <= n; ++i) {
}else {
sumOdds += i;
}
}
(This assumes all values are integer)
int num_odds = ((n - 1) >> 1) + 1; /* number of odd numbers from 1 to n */
int num_evens = n >> 1; /* number of even numbers from 1 to n */
int sum_odds = num_odds * num_odds;
int sum_evens = (num_evens * num_evens) + num_evens;
summing 10 numbers with variables
#include
main()
{
int a,b,c,d,e,f,g,h,i,j,add;
printf("Enter 10 numbers to sum:\t");
scanf("%d %d %d %d %d %d %d %d %d %d",&a,&b,&c,&d,&e,&f,&g,&h,&i,&j);
add = a+b+c+d+e+f+g+h+i+j;
printf("%dResult:\t",add);
}
Is the use of a header files absolutely necessary?
No. But in large programs it helps to split the code into logically organised modules (translation units). In order to ensure declarations remain consistent across all translation units, headers must be used.
Code of Round-robin scheduling in c?
#include<stdio.h>
#include<conio.h>
main()
{
int st[10],bt[10],wt[10],tat[10],n,tq;
int i,count=0,swt=0,stat=0,temp,sq=0;
float awt=0.0,atat=0.0;
clrscr();
printf("Enter number of processes:");
scanf("%d",&n);
printf("Enter burst time for sequences:");
for(i=0;i<n;i++)
{
scanf("%d",&bt[i]);
st[i]=bt[i];
}
printf("Enter time quantum:");
scanf("%d",&tq);
while(1)
{
for(i=0,count=0;i<n;i++)
{
temp=tq;
if(st[i]==0)
{
count++;
continue;
}
if(st[i]>tq)
st[i]=st[i]-tq;
else
if(st[i]>=0)
{
temp=st[i];
st[i]=0;
}
sq=sq+temp;
tat[i]=sq;
}
if(n==count)
break;
}
for(i=0;i<n;i++)
{
wt[i]=tat[i]-bt[i];
swt=swt+wt[i];
stat=stat+tat[i];
}
awt=(float)swt/n;
atat=(float)stat/n;
printf("Process_no Burst time Wait time Turn around time
");
for(i=0;i<n;i++)
printf("%d %d %d %d
",i+1,bt[i],wt[i],tat[i]);
printf("Avg wait time is %f
Avg turn around time is %f",awt,atat);
getch();
}
Can borland compiler perform the graphics in c?
No. But programs compiled with Borland compilers might be able, platform-dependent.
How do write a program to output prime numbers between 1-1000 using c?
main()
{
int i,n,p,v;
printf("enter the number of terms");
scanf("%d",&n);
for(i=2;i<=n;i++)
{
for(j=1;j<i;j++)
{
if(i%j==0)
v=v+1;
else
p=p+1;
}
}
printf("%d is a prime",i);
}
check this out
Write a C program to find volume of sphere?
double Pi = 3.1415...;//Pi number
double sphereRadius = 0;
double surfaceAreaOfSphere = 0;
...
cout << "Enter a radius of the sphere";
cin >> sphereRadius;
...
surfaceAreaOfSphere = 4*Pi*sphereRadius*sphereRadius;
//or using math.h
surfaceAreaOfSphere = 4*Pi*pow(sphereRadius, 2);
...
cout << "The surface area is: " << surfaceAreaOfSphere;
...
Is it possible to immediately run a program without compiling it?
Not in C++, unless you have an interpreter. Most C++ development systems, however, are based on the compiler idiom, so, the answer is no.
However, Java is very close to C++, except for the platform and libraries, so one might consider Java to be an interpreter, however, you still must "compile" Java to byte code, so the answer is still no.
Relation between array and pointer?
A pointer identifies the location of some data in memory, similarly to an envelope with a street address on it. An array is several values of the same type, stored next to each other in memory. A useful consequence is that all of an array's elements may be found by simply counting up from the address of the first element.
Note that, when an array value is made available outside of its original scope, it decays to a pointer to its first element. So, for example, sizeof returns a different size for an array depending on which scope you call it in. In the array's original scope, it returns the number of elements in the array; in any other scope it returns the number of bytes used to store the pointer.
Write a c program that interchanges the odd and even elements of an array?
#include<stdio.h>
int main()
{
int num[]={1,2,3,4,5,6};
int i,temp;
for(i=0;i<=5;i=i+2)
{
temp=num[i];
num[i]=num[i+1];
num[i+1]=temp;
}
for(i=0;i<=5;i=i+2)
printf(''%d",num[i]);
return 0;
}
Can break statement be used without any loop?
The Break statement should generally get executed in some loop or switch statement.
The below code will give compiler error.
void main()
{
printf("12");
break;
printf("14");
}
What is built-in function in c?
There are no built-in functions in C++. The definition of a built-in function is a function that does not need to be declared before it is used, but every function in C++ is user-defined and must be declared before it can be used. This includes functions provided by the C++ standard library which we declare by including the appropriate headers.
Some articles mistakenly describe keywords such as while, switch and if as being built-in functions, however these are statements, not functions.
C++ does provide several built-in operators, some of which look and behave very much like functions. For example, the built-in sizeof() operator can be used without any declaration and looks very much like a function, but its argument is not a value, it is a type name, and we cannot (easily) define a function that accepts a type name as an argument.
The built-in typeid() operator also takes a type name argument, but it is often mistakenly regarded as being a user-defined function because we must include the C++ standard library
Unlike sizeof() and typeid(), the default global new and delete operators can be overridden with user-defined function operators, thus these are also mistakenly regarded as being built-in functions. However, only the overrides are functions because that's the only way to define an operator overload; the default global operators are built-in operators, not built-in functions.
The semantic difference between a built-in operator and a built-in function may seem insignificant, however a real built-in function would be no different to a user-defined function other than the fact that it need not be declared before using it. But a user-defined function also has identity (a memory address) and we can pass that identity to other functions using a function pointer argument. But we cannot pass a built-in operator to a user-defined function because it has no identity, thus it cannot be regarded as being a built-in function.