answersLogoWhite

0

📱

C Programming

Questions related to the C Computer Programming Language. This ranges all the way from K&R to the most recent ANSI incarnations. C has become one of the most popular languages today, and has been used to write all sorts of things for nearly all of the modern operating systems and applications. It it a good compromise between speed, power, and complexity.

9,649 Questions

How sorted data effects binary search tree?

If the data is sorted, you don't need a tree, you can use a sorted array with constant time random access and zero overhead. To perform a binary search, start with the middle element (what would be the root of a balanced tree). If that's not the value you're looking for, repeat the search with the left subarray if the middle element is larger, or the right subarray if not. This reduces the number of elements to search by half on each iteration. If the chosen subarray is empty, the value you're looking for does not exist. If the value does exist, you will eventually find it in the middle of the remaining subarray.

ACL stands for?

ACL stands for Anterior Cruciate Ligament

Write a program to dycrypt the text kpfkc to get original string India using string concept in c?

char cyphertext[] = "kpfkc";

char plaintext[sizeof(cyphertext)];

int i;

for (i=0; i<sizeof(cyphertext); i++) plaintext[i] = cyphertext[i] - 2;

Note: This is not portable, and depends on the USASCII character set.

Difference between top down and bottom up parsing in compiler design?

Bottom-up parsing

This approach is not unlike solving a jigsaw puzzle. We start at the bottom of the parse tree with individual characters. We then use the rules to connect the characters together into larger tokens as we go. At the end of the string, everything should have been combined into a single big S, and S should be the only thing we have left. If not, it's necessary to backtrack and try combining tokens in different ways.

With bottom-up parsing, we typically maintain a stack, which is the list of characters and tokens we've seen so far. At each step, the stack is "reduced" as far as possible by combining characters into larger tokens.

Top-down parsing

For this approach we assume that the string matches S and look at the internal logical implications of this assumption. For example, the fact that the string matchesSlogically implies that either (1) the string matches xyz or (2) the string matchesaBC. If we know that (1) is not true, then (2) must be true. But (2) has its own further logical implications. These must be examined as far as necessary to prove the base assertion.

Example

String is acddf.

Steps

· Assertion 1: acddf matches S

oAssertion 2: acddf matches xyz:

oAssertion is false. Try another.

oAssertion 2: acddf matches aBC i.e. cddf matches BC:

  • Assertion 3: cddf matches cC i.e. ddf matches C:

§ Assertion 4: ddf matches eg:

§ False.

§ Assertion 4: ddf matches df:

§ False.

  • Assertion 3 is false. Try another.
  • Assertion 3: cddf matches cdC i.e. df matches C:

§ Assertion 4: df matches eg:

§ False.

§ Assertion 4: df matches df:

§ Assertion 4 is true.

  • Assertion 3 is true.

oAssertion 2 is true.

· Assertion 1 is true. Success!

Parse trees

S

|

S

/|\

a B C

| |

S

/|\

a B C

| |

c

S

/|\

a B C

/| |

c d

S

/|\

a B C

/| |\

c d d f

Binary search iterative method over recurssive method?

#include <iostream>

#include <conio.h>

int linearSearch( const int array[], int length, int value);

int main()

{

const int arraySize = 100;

int a[arraySize];

int element;

for( int i = 0; i < arraySize; i++)

{

a[i] = 2 * i;

}

element = linearSearch( a, arraySize, 10);

if( element != -1 )

cout << "Found value in element " << element << endl;

else

cout << "Value not found." << endl;

getch();

return 0;

}

int linearSearch( const int array[], int length, int value)

{

if(length==0) return -1;

else if (array[length-1]==value) return length-1;

else return urch( array, length-1, value);

}

it is in c++ language ,u can change it to c by including stdio.h ,printf & scanf.....i think it wud be beneficial

have a look their too. similar program like that and easy understanding

http://fahad-cprogramming.blogspot.com/2014/02/linear-search-program-in-c-using.html

What variable keeps a running total?

The answer is "an accumulator."

"A running total is a sum of numbers that ACCUMULATES with each iteration of a loop. The variable used to keep the running total is called an accumulator."

It can be any variable you want! It could be total, tot, etc. Here is an example:

total = 0

randoms = [random.randRange(0, 99999)] * 100 # Creates a list of 100 random numbers

for number in randoms:

total += number

print(total) # Py3k print statement. Sample output: 35460

How do you execute 2 for loops together?

If you mean how do you simultaneously execute 2 for loops, you cannot. At best you can execute 2 for loops concurrently, where each loop executes (independently) within two separate threads.

It is possible to execute two loops within the same statement, however this is really just one loop based upon two conditions:

int x, y;

for (x=0, y=0; x<100 && y<100; ++x, ++y) {

/* ... */

}

You probably mean how do you execute a loop within a loop (a nested loop). this is achieved as follows:

int x, y;

for (x=0; x<100; ++x) {

for (y=0; y<100; ++y) {

/* ... */

}

}

Note that the body of this loop will execute 100 x 100 = 10,000 times.

What are the design issue for array?

What is its size? How is its size determined and when (compile/run-time). What does the software using the array do when the array is empty? partially full? full? Avoid the software addressing elements of the array which are undefined, or addressing elements outside the bounds of the array When and who is responsible for allocating and freeing memory when the array is no longer needed (program or called procedure start/termination) or some other time determined during program execution. If the array is implementing a data structure such as a stack, queue, dequeue, list, etc. What is its implementation of the usual data structure operations, Create, Empty, List Items, Top, First, Last, Next, etc.

Double-ended queue using c language?

/* c++ program to implement double ended queue using doubly linked list with templates*/
#include
#include
#include
template
struct node
{
t data;
node *llink;
node *rlink;
};


template
class dequeue
{
private:
node *front,*rear;
public:
dequeue()
{
front=rear=NULL;
}


node *getnode()
{
node *newnode=new node;
newnode->llink=NULL;
newnode->rlink=NULL;
return newnode;
}


void insfrnt();
void insrear();
void delfrnt();
void delrear();
void disfrnt();
void disrear();
};


template
void dequeue::insfrnt()
{
node *newnode=getnode();
cout<<"Enter The Element That Has To Enqueued At The Front"<cin>>newnode->data;
if(front==NULL && rear==NULL)
front=rear=newnode;
else
{
newnode->rlink=front;
front->llink=newnode;
front=newnode;
}
}


template
void dequeue::insrear()
{
node *newnode=getnode();
cout<<"Enter The Element That has to be Enqueued at the Rear"<cin>>newnode->data;
if(front==NULL && rear==NULL)
front=rear=newnode;
else
{
rear->rlink=newnode;
newnode->llink=rear;
rear=newnode;
}
}


template
void dequeue::delfrnt()
{
if(front==NULL)
cout<<"Dequeue Underflow"<else
{
node *temp;
temp=front;
if(front==rear)
front=rear=NULL;
else
{
front=temp->rlink;
front->llink=NULL;
}
cout<data<<" is the element deleted from the dequeue"<delete temp;
}
}


template
void dequeue::delrear()
{
if(rear==NULL)
cout<<"Dequeue Underflow"<else
{
node *temp,*prev;
temp=rear;
if(front==rear)
front=rear=NULL;
else
{
rear=temp->llink;
rear->rlink=NULL;
}

cout<data<<" is the element deleted from the dequeue"<delete temp;
}
}


template
void dequeue::disfrnt()
{
if(front==NULL)
cout<<"Dequeue Underflow"<else
{
node *temp;
temp=front;
cout<<"front";
while(temp!=NULL)
{
cout<<"->"<data;
temp=temp->rlink;
}
cout<<"<-rear"<}
}


template
void dequeue::disrear()
{
if(rear==NULL)
cout<<"Dequeue Underflow"<else
{
node *temp;
temp=rear;
cout<<"rear";
while(temp!=NULL)
{
cout<<"->"<data;
temp=temp->llink;
}
cout<<"->front"<}
}


void main()
{
dequeue dq_int;
dequeue dq_float;
dequeue dq_char;
int choice;
do
{
clrscr();
cout<<"DEQUEUE :"<cout<<"\t Double Ended Queue (abb :- deque ; pronounced as deck) is an abstract data structure for which elements can be added at the front as well as at the rear. It is often called as Head-Tailed Linked List"<cout<<"\t========================"<cout<<"\t\tDequeue Menu"<cout<<"\t========================"<cout<<"[1] Dequeue Of Integer Values"<cout<<"[2] Dequeue Of Floating Values"<cout<<"[3] Dequeue Of Characters"<cout<<"[4] Exit"<cout<<"\t Enter Your Choice"<cin>>choice;
switch(choice)
{
case 1:
clrscr();
int chi;
do
{
cout<<"\t======================="<cout<<"\tDequeue Of Integer Values"<cout<<"\t======================="<cout<<"[1] Insert Element At Front"<cout<<"[2] Insert Element At Rear"<cout<<"[3] Delete Element At Front"<cout<<"[4] Delete Element At Rear "<cout<<"[5] Display Element(s) At Front"<cout<<"[6] Display Element(s) At Rear"<cout<<"[7] Back To Main Menu"<cout<<"\tEnter Your Choice"<cin>>chi;
switch(chi)
{
case 1: dq_int.insfrnt();
break;
case 2: dq_int.insrear();
break;
case 3: dq_int.delfrnt();
break;
case 4: dq_int.delrear();
break;
case 5: dq_int.disfrnt();
break;
case 6: dq_int.disrear();
break;
}
}
while(chi<=6);
break;




case 2:
clrscr();
int chF;
do
{
cout<<"\t======================="<cout<<"\tDequeue Of Floating Values"<cout<<"\t======================="<cout<<"[1] Insert Element At Front"<cout<<"[2] Insert Element At Rear"<cout<<"[3] Delete Element At Front"<cout<<"[4] Delete Element At Rear "<cout<<"[5] Display Element(s) At Front"<cout<<"[6] Display Element(s) At Rear"<cout<<"[7] Back To Main Menu"<cout<<"\tEnter Your Choice"<cin>>chi;
switch(chi)
{
case 1: dq_float.insfrnt();
break;
case 2: dq_float.insrear();
break;
case 3: dq_float.delfrnt();
break;
case 4: dq_float.delrear();
break;
case 5: dq_float.disfrnt();
break;
case 6: dq_float.disrear();
break;
}
}
while(chi<=6);
break;


case 3:
clrscr();
int chc;
do
{
cout<<"\t======================="<cout<<"\tDequeue Of Integer Values"<cout<<"\t======================="<cout<<"[1] Insert Element At Front"<cout<<"[2] Insert Element At Rear"<cout<<"[3] Delete Element At Front"<cout<<"[4] Delete Element At Rear "<cout<<"[5] Display Element(s) At Front"<cout<<"[6] Display Element(s) At Rear"<cout<<"[7] Back To Main Menu"<cout<<"\tEnter Your Choice"<cin>>chc;
switch(chc)
{
case 1: dq_char.insfrnt();
break;
case 2: dq_char.insrear();
break;
case 3: dq_char.delfrnt();
break;
case 4: dq_char.delrear();
break;
case 5: dq_char.disfrnt();
break;
case 6: dq_char.disrear();
break;
}
}
while(chi<=6);
break;





case 4: exit(0);
break;


}
}
while(choice<=3);
}

Which member can not be access from main in c plus plus?

A private member can only be accessed from within a method of the class.

(Not 100% certain what the question means. If this answer is not sufficient, please restate the question, giving more details as to what is being asked.)

The binary value of -3 is?

1101 in 4 bits,

11111101 in 8 bits,

and so on: add leading 1's as necessary

Advantages of Typeless programming language?

* In a typeless language, a variable can contain any kind of value (numeric, string, boolean). * Typeless languages are very flexible and dynamic, resulting in quick turn around of code.

Can you divide pointer variables?

No, but if you really want that, use type-cast, for example:

printf ("main=%p=5*%lx\n", main, ((long)main)/5);

Of course it is good for nothing at all.

When we insert a new node in a binary search tree will it become an internal node or terminal node?

It will be come a terminal node. Normally we call terminal nodes leaf nodes because a leaf has no branches other than its parent.

What is different between while and for loop in c plus plus?

Although both can achieve very similar loops, the one you use for a specific loop usually comes down to whichever seems more intuitive to you. In terms of performance, one method may be slightly more efficient than the other, however there are no general rules that can be applied; you must test each case by comparing the machine code or by physically timing the loops with a high performance event timer (HPET). In my experience, the performance difference is so negligible it is not worth the effort. Background activity has a far greater impact on performance.

Describing the differences between every possible loop you might create would take me a lifetime, but there are a couple of subtle differences that are worth pointing out.

Infinite Loops

for(;;){

} // infinite for loops do not require a condition.

while( true ){

} // infinite while loops MUST have a condition.

To break out of an infinite loop you must test for one or more conditions within the loop itself, and call break to exit the loop when a condition is met. You can also call continue to start the next iteration before reaching the end of the current iteration.

Stepping Loops

When stepping through a series of values, the for() loop is usually the better choice, especially if the step must occur AFTER each iteration. Consider the following similar loops:

for( int x=0; x<10; ++x ){

// if we place continue here, ++x will execute before the next iteration begins.

}

int x=0;

while( x<10 ){

// if we use a continue here, ++x will not execute. We could be here forever!

++x;

}

Another point to bear in mind here is that with the for()loop, x will fall from scope when the loop finishes. If x must remain in scope, initialise x before entering the for() loop. With the while() loop, x is still in scope when the loop finishes so if x must fall from scope, do not use the while() loop.

do...while Loops

The do...while loop is quite different from for()and while() loops, so it is worth mentioning here. Both for() and while() loops test a condition BEFORE the loop begins execution. If the condition is false, the loop may not execute at all. But a do...while loop is guaranteed to enter the loop AT LEAST once, because the condition is tested AFTER the loop begins, at the end of the loop just before it begins to iterate.

int x = 0;

do{

// Whatever you place here will execute at least once.

// If we place continue here, execution jumps to the while(condition) first.

}while(++x != 10)

In dos what is the function of a parameter?

A parameter is a command-line switch or an argument to a function. We use parameters to specify the input variables for the commands or functions we invoke. For instance, when we want to list the contents of a directory or folder, we have to pass the directory or folder path to the appropriate command so that it knows which directory or folder to process.

How many headerfiles in c language?

* complex.h
* ctype.h
* fenv.h
* float.h
* math.h
* setjmp.h
* signal.h
* stdarg.h
* stdio.h
* stdlib.h
* string.h
* tgmath.h
* time.h

List some carnivores?

Carnivores are meat eaters such as tigers,lions,bears,etc,.