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

What does printf function return?

Two possibilities: on success, it'll return the amount of characters printed. On failure, a negative number is returned.

What statement is used to skip a part of loop?

The continue statement is used to skip the balance of a loop.

What if the elements are repeated in binary search?

You will find one of them (not necessarily the first or the last).

What is array Explain with syntax?

an array is a collection of the same data type.

What does vast array mean?

a regular and imposing arrangement; disposition in regular lines

Difference between message oriented middleware and remote procedure call?

Feature MOM RPC

Metaphor post office like Telephone like

Cilent server

time relationships ASynchronous Synchronous

Client server

sequence No sequence server must first comes up

before the client talks to it.

Partner needed No Yes

Message filtering yes No

Load

balancing Single queue is needed Require TP monitor

implement FIFO policy

Performance Slow Fast

Style queued call return

What are the uses of sentinel value?

A sentinel value is a value that is not supposed to change. It can be allocated along with, and used before the beginning and after the ending of a region of memory to detect if the program logic modified memory outside of the intended region. Most compilers and run-time libraries will do this automatically when you do a debug compile/link.

How do you draw a cycle in a c program?

/*PROGRAM TO IMPLEMENT GAUSS-jordan method.

#include
#define MX 20
main()
{
float a[MX] [MX+1],m,p;
int i,j,k,n;
puts("\n how many equations?:");
scanf("%d",&n);
for(i=0;i<=n-1;i++)
{
printf("Give the coefficients of the equation no%d:\n",i+1);
for(j=0;j<=n;j++)
scanf("%f",&a[i][j]);
}
for(k=0;k<=n-1;k++)
{
for(i=0;i<=n-1;i++)
{
m=a[i][k]/a[k][k];
p=a[k][k];
for(j=k;j<=n;j++)
{
if(i==k)
a[i][j]=a[i][j]/p;
else
a[i][j]=a[i][j]-m*a[k][j];
}
}
}
for(i=0;i<=n-1;i++)
printf("\n X[%2d]=%5.2f",i,a[i][n]);

}

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