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 do you simplify n factorial divided by n minus 1 factorial?

How about you pay attention in class so you don't have to ask the computer for the answers.be smart listen to your teacher.

Just kidding ,i'm just thirteen what do i know

When a reference variable is passed to any function than whether it pass address or a copy of a variable?

You cannot arbitrarily determine what is passed to a function from outside of the function. If the function expects a reference, then the memory address of the variable will be automatically passed to the function. If the function expects a value, then a copy of the variable's value is automatically passed instead. In other words, it is the function signature that determines what is passed, not how you call the function.

What does hexadecimal base 16 convert binary equal?

16 is the 4th power of 2. So a hexadecimal number is converted to binary by replacing each hex digit by the 4-bit binary number having the same value. Conversely, in converting binary to hexadecimal, we group every 4 bits starting at the decimal (binary?) point and replace it with the equivalent hex digit. For example, the hexadecimal number 3F9 in binary is 1111111001, because 3 in binary is 11, F (decimal 15) is 1111, and 9 is 1001.

Is it possible to place a return statement anywhere in 'C' program?

No. Return statements can only appear within a function body, but they can be placed anywhere within that body. If the function returns a value, then the return statement must also return a value of the same type.

Which would NOT be a valid comparison to control a While Loop?

while (mind-reading-isn't-possible) your-question-cannot-be-answered;

What is literal character string in select list?

example:

SELECT name, '*', address FROM table;

Here '*' is a literal character.

What programming language can be used for water billing system?

Any programming language can be used. Some are more suitable than others.

How do you represent binary tree using array?

The root of the tree is stored in array element [0];

for any node of the tree that is stored in array element [i],

its left child is stored in array element [2*i],

its right child at [2*i+2]

Should you avoid local variable scope?

No. In most designs, local variables are considered a good thing thanks to the isolation that they provide (no other code can "abuse" your variable). However, it is important to distinguish between local static variables, local automatic variables, and locally made references to the heap.

Local static variables are initialized only once at application initialization time, and retain their most recently assigned value over multiple invocations of the function which contains them. Local static variables must be used with care and can lead to non-reentrant code (the famous example being the strtok() CRT function). However, these variables are usually great to track the total number of something, or the minimum or maximum value of a particular item, etc.

In C, local automatic variables are the most common form of local variables. These are typically allocated on the stack, so care must be taken when declaring large automatic variables, or when using recursion.

When the size of a local automatic variable is a concern, dynamic memory management method should be considered those maintain a local auto pointer on the stack but place the data in the heap. This method allows to allocate large amounts of data without burden on the stack, and the lifetime of such data is no longer limited by the lifetime of the scope in which it was allocated.

Very rare cases exist where local variables are generally avoided; these are mostly in the area of very resource limited embedded programming.

How do you write a c program for banker's algorithm?

/*this is a perfect code. No bugs.....*/

#include<stdio.h>

#define MAX 10

void main()

{

int f1,k,l,i,j,no_of_res,no_of_proc,temp,f,seq;

temp=0;

f=0;

f1=1;

printf("\nEnter the no of Resources: ");

scanf("%d",&no_of_res);

printf("\nEnter the no of process: ");

scanf("%d",&no_of_proc);

int flag[no_of_proc],sequence[no_of_proc],claim[no_of_proc][no_of_res],allocation[no_of_proc][no_of_res];

int needed[no_of_proc][no_of_res],resource[no_of_res],available[no_of_res];

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

{

flag[i]=-1;

}

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

{

sequence[i]=-1;

}

printf("\nEnter the Claimed Matrix for Process:");

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

{

printf("\nEnter the value for Process %d:",i+1);

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

{

printf("\nEnter the value of Resource :%d:",j+1);

scanf("%d",&claim[i][j]);

}

}

printf("\nEnter the Maximum Resource available:");

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

{

printf("\nEnter the value of Resource :%d:",i+1);

scanf("%d",&resource[i]);

}

printf("\nEnter the Allocation Matrix for Process:");

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

{

printf("\nEnter the value for Process %d:",i+1);

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

{

printf("\nEnter the value of Resource Allocated :%d:",j+1);

scanf("%d",&allocation[i][j]);

}

}

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

{

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

{

temp=temp+allocation[j][i];

}

available[i]=resource[i]-temp;

if(available[i]<=0)

available[i]=0;

temp=0;

}

printf("\nThe Cliamed Matrix of Resources is:");

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

{

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

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

{

printf("%d\t",claim[i][j]);

}

}

printf("\nvalue of Maximum Resource Available :\n");

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

{

printf("%d\t",resource[j]);

}

printf("\nAllocation Matrix for Proccess:");

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

{

printf("\n");

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

{

printf("%d\t",allocation[i][j]);

}

}

printf("\nvalue of Available resources after alloction:\n");

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

{

printf("%d\t",available[j]);

}

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

{

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

{

needed[i][j]=claim[i][j]-allocation[i][j];

if(needed[i][j]<=-1)

needed[i][j]=0;

}

}

printf("\n Needed Matrix after allocation:\n");

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

{

printf("\n");

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

{

printf("%d\t",needed[i][j]);

}

}

i=0;

seq=0;

while(i<no_of_proc)

{

if(flag[i]==-1)

{

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

{

if(needed[i][j]<=available[j])

f=0;

else

{

f=1;

break;

}

}

if(f==0)

{

printf("\n====================================================================\n");

flag[i]=i+1;

sequence[seq]=i+1;

seq=seq+1;

printf("\nProcess P%d will Run until Complition",i+1);

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

{

available[j]=available[j]+allocation[i][j];

allocation[i][j]=0;

needed[i][j]=0;

}

printf("\nThe needed Matrix of Resources is:");

for(k=0;k<no_of_proc;k++)

{

printf("\n");

for(l=0;l<no_of_res;l++)

{

printf("%d\t",needed[k][l]);

}

}

printf("\nAllocation Matrix for Proccess:");

for(k=0;k<no_of_proc;k++)

{

printf("\n");

for(l=0;l<no_of_res;l++)

{

printf("%d\t",allocation[k][l]);

}

}

printf("\nvalue of Available resources after alloction:\n");

for(l=0;l<no_of_res;l++)

{

printf("%d\t",available[l]);

}

i=0;

}

if(f==1)

i++;

f=1;

}

else

{

i++;

}

}

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

{

if(sequence[i]==-1)

break;

else

f1=0;

}

if(f1==1)

printf("\nSystem is not in Safe state.....");

if(f1==0)

{

printf("\nSystem is in Safe state.....");

printf("\n The Sequence of Completion of Process is:");

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

{

printf("P%d ",sequence[i]);

}

}

printf("\n");

}

Written by: Fabianski Benjamin

How can you use a single scanf statement to read in three integers from the keyboard?

#include<stdio.h>

#include<conio.h>

int main(void) {

int a,b,c;

printf("write three numbers:\n");

scanf("%d %d %d", &a,&b,&c);

printf("You entered %d , %d and %d",a,b,c);

getch();

}

Why nested comment are not allowed on C language?

C and C++ do it for ease of parsing. This way, when they hit a comment start of /*, the parser can trivially scan to the end. Otherwise, it would have to set up and maintain a stack, and then report errors if the comment tokens are unmatched.

As to why Java does it, the answer is simple - Java's syntax was designed to emulate C and C++, to trick people into thinking it was just as fast (in the beginning, Java was purely interpreted, so this trick WAS necessary to get traction). If nested comments were allowed, it might trip up some C programmers, and many angry blog posts would be written!

What are the advantages of a list over an array for implementing a priority queue?

A priority queue not only requires insertion of a new element at the end of the queue, but may require insertion at the head or somewhere in the middle, subject to the priority of the new item.

This can be implemented efficiently using a list, but would generally require more expensive operations when implemented using an array, such as moving existing elements of lower priorities "one down" to make room for the new element.

Having said that, many other implementations of priority queues are possible, which might be perfectly suited for implementation with an array. For example, if the number of different priority levels is finite and small (three levels for low, middle and high, for example), one might consider implementing three queues instead, one for each priority level. This would allow for efficient implementation with statically allocated and sized arrays, which is often the preferred approach in embedded programming.

What also called two dimensional arrays are?

I suppose you could refer to a two-dimensional array as a rectangular or square array (or as a jagged array of not all arrays within a given dimension have the same size). Table, grid or matrix may also be good synonyms for two-dimensional array, subject to the problem domain addressed with the algorithm.