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 is a linear queue?

A linear queue models the FIFO(first in first out) data structure, much like a line in real life. The first person in line will be the first person served, in queues the first element to be added is the first that can be removed. The only adding point is to the end of the list and the only removal point is the beginning of the list.

Queue<String> q = new LinkedList<String>(); // The LinkedList class implements Queue

q.add("Bob"); // Now Bob is at the front of the queue

q.add("Stacy"); // Stacy after Bob

q.add("Will"); // and Will after her

String removed = q.remove(); // Bob is removed

q.add("Michael"); Michael is added after Will

System.out.println(q); // Prints ["Stacy", "Will", "Michael"]

What value is assigned to extern variable?

Default initial value of extern integral type variable is zero otherwise null.

Why you use constructor instead of function?

For every class an empty constructor will be defined automatically by default unless you provide a constructor definition manually. Constructor in a class can be used to initialize variables or perfrom some basic functionallity whenever an object is created.

What is Multilevel feedback queue?

A multi-level feedback queue scheduling policy gives preference to short and I/O bound processes, it also rapidly establishes the nature of a process and schedules it accordingly. Multi-level feedback queues work on priorities. Processes are placed in separate queues based on their priority, this in turn is based on their CPU consumption and If a process uses too much of the CPU, it will be given a lower priority and therefore get less CPU time than fast and I/O bound processes. Any processes that do not complete in their allocated time slice / quantum are demoted to a queue of less priority, these lower priority queues generally have larger quantums / time slices. Each of the queues may use a different scheduling algorithm, this is done to make the overall scheduling method as efficient as possible. The features that may vary between different multi-level feedback queue scheduling methods are: - The number of queues - The scheduling algorithm assigned to each queue - The method used to promote/demote processes to different queues - The method that determines which queue a process enters --- Thomas Lee

What is formal parameter in c?

A variable declared in the header of a method whose initial value is obtained during method invocation (using the actual parameter). So: int method(/*Formal Parameters*/){ //Method Actions return 0; }

What are the difference between signed and unsigned data types?

A signed integer represents both positive and negative values, while an unsigned integer represents only positive values. Range depends on the number of bits the compiler assigns for the representation.

bits max-negative max-positive max-unsigned

8 -128 +128 255

16 -32768 +32767 65535

32 -2147483648 +2147483647 4294967295

64 -9223372036854775808 +9223372036854775807 18446744073709551615

When you double click your c drive it says application cannot be run in Win32 mode?

I also had this problem few dayz before and it just made me mad, i was felt into that situation that i even cannot format ma windows so, finally i researched upon it and found the solution :-

1. Go to your first drive for example c:/ and delete the hiden file autorun.inf also delete from recycle bin

2. Then create a folder name autorun.inf after delete first one as soon as possible

3. do the same thing with all of your drives

4. Log off ur PC your PC

bingo ! you have your PC recovered back

What is the function of a RAC recovery program?

The function of the RAC recovery program is to find over payments and under payments in the Unites States health care industry to improve the budget issues and efficiency.

What is the difference between base class and derived class in c plus plus?

There is no difference other than that a derived class inherits from a base class. That is, the derived class inherits all the public and protected members of its base class, and is a more specialised form of its base class. Thus both can be treated as if they really were base classes. The derived class can also override the virtual methods of the base class, thus allowing polymorphic behaviour without the need to know the exact type of the derived class.

How do you write a C plus plus program to display the Fibonacci sequence to 10 terms and then display the 20th term?

#include<iostream>

#include<vector>

#include<cassert>

using namespace std;

// Returns a vector of Fibonacci numbers from start to max.

// Sequence A000045 in OEIS if start is 0.

vector<unsigned> fibonacci (const unsigned start, const unsigned max)

{

// Invariants:

if (1<start)

throw std::range_error

("vector<unsigned> fibonacci (const unsigned start, const unsigned max): start < 1");

if (max<start)

throw std::range_error

("vector<unsigned> fibonacci (const unsigned start, const unsigned max): max < start");

// Empty set...

vector<unsigned> fib {};

if (max)

{

// First term...

fib.push_back (start);

if (1<max)

{

// Second term...

fib.push_back (1);

// All remaining terms...

unsigned next = 0;

while ((next = fib.back()+fib[fib.size()-2]) <= max)

fib.push_back (next);

}

}

return fib;

};

// Return true if the given number is prime.

bool is_prime (const unsigned num)

{

if (num<2) return false;

if (!(num%2)) return num==2;

for (unsigned div=3; div<=sqrt(num); div+=2)

if (!(num%div)) return false;

return true;

}

// Displays all prime Fibonacci numbers in range [1:10,000].

int main()

{

const unsigned max=10000;

vector<unsigned> f = fibonacci (1, max);

cout << "Prime Fibonacci numbers in range [1:" << max << "]\n";

for (auto n : f)

if (is_prime (n))

cout << n << ", ";

cout << "\b\b " << endl; // backspace and overwrite trailing comma

}

C program on shortest-job-first scheduling algorithm?

#include #include #include void main() { char p[10][5],temp[5]; int tot=0,wt[10],pt[10],i,j,n,temp1; float avg=0; clrscr(); printf("enter no of processes:"); scanf("%d",&n); for(i=0;i\n",i+1); scanf("%s",&p[i]); printf("enter process time"); scanf("%d",&pt[i]); } for(i=0;ipt[j]) { temp1=pt[i]; pt[i]=pt[j]; pt[j]=temp1; strcpy(temp,p[i]); strcpy(p[i],p[j]); strcpy(p[j],temp); } } } wt[0]=0; for(i=1;i\t P_time\t w_time\n"); for(i=0;i\t%d\t%d\n",p[i],et[i],wt[i]); printf("total waiting time=%d\n avg waiting time=%f",tot,avg); getch(); }

Write a c program divisible by 3 and 5 or not?

void main(){ int i,j; scanf("%d",&i); if((i%5)==0) printf("the given number is divisible by 5); }

How do you Write a program to read natural numbers from a keyboard Find the largest and the smallest number?

This sounds like a homework assignment, so I will give you some pseudo code instead of straight C code.

[code]

OPEN FILE FOR READING

IF NOT END OF FILE THEN

min = READ FILE INPUT

max = min

ENDIF

WHILE NOT END OF FILE

x = READ FILE INPUT

IF x < min THEN

min = x

ENDIF

IF x > max THEN

max = x

ENDIF

ENDWHILE

CLOSE FILE

[/code]

If you are using C, then you will need to use fopen(), scanf(), fclose() and maybe feof(). If you are using C++ then you can use fstream, must like you would use cin, except that you have to open the stream, check for end of file and close it.

Three elements that must be included in order for a loop to successfully perform correctly?

Well, in C for example the while-loop looks like this:

while (condition) statement

The following ones are all wrong:

condition (while) statement

while (statement) condition

statement (condition) while

...

Write a c program to reverse the any number without using loops?

#include<stdio.h>

#include<conio.h>

void main(){

int a[100],i,temp,j,n;

printf("\t \n enter the size of the array");

scanf("%d",&n);

printf("\n enter the numbers ");

for(i=0;i<n;i++){

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

}

j=n-1;

for(i=0;i<(n/2);i++){

temp=a[i];

a[i]=a[j];

a[j]=temp;

j--;

}

for(i=0;i<n;i++){

printf("\n %d",a[i]);

}

}

What are the different types of data types used in c.net?

In C#, data types can be categorised as

  1. Value Types.
  2. Reference Types.

Value Types

Variables defined from Value Types store values. Copying one value type caribale tp another, doesn't affect the priginal vraible.

They can be further categorised into: -

1) structs: - They can be numeric (int, float, decimal), bool, user-defined structs.

2) Enumerations: - They consist of a set of named constants. By default the first enumerator has value=0.

Reference Types

These objects store references to the actual data. These can be categorised into: -

1) Classes: -- They encapsulate data and its functionality into a single entity called OBJECT.

2) Interfaces: - These are used to declare the signatures, blurprints of methods, delegates and events.

3) Delegates: - These contain the addresses/references to a method.

For more information refer to related links.

What are the disadvantages of switch statement in C-language?

In some languages and programming environments, a case or switch statement is considered easier to read and maintain than an equivalent series of if-else statements, because it is more concise.

However, when implemented with fall-through, switch statements are a frequent source of bugs among programmers new to the switch statement.

What are different ways by which you can access public member functions of an object?

You simply access it. That's what public means. You can access a public member from any other class, or even from non class code, so long as the referenced class is in scope to the referencing code. In order to do that, you need to have a reference (directly or indirectly) to the instance of the class you want to reference. This would generally be passed as an argument to the referencing code.

What is counter loop?

A counted loop is a loop that executes the loop's statement a pre-determined number of times. The count represent the exit condition of the loop. A loop that is not counted is an infinite loop.

What is function of include in c language?

The #include directive is used to tell the preprocessor that the specified file's contents are to be included at the point where the directive appears, just as if you'd typed those contents in full yourself.

Include files are primarily used to organise declarations of external variables and functions, complex data types, constants and macro definitions. The code need only be declared once, and included wherever required. Think of include files as a means of providing forward declarations without having to retype those declarations in full. The definitions of those declarations needn't be contained in the included file, but they must be made available to the program, either as a linked library or as a separate source code file which includes those same declarations.

The include keyword is used in C to tell the linker what libraries your code is going to be using.

What is an example program in c plus plus to square a number using the concept of an inline function?

... double squareOf_Number(double Number)

{

return (Number*Number);

}

...

int main()

{

...

double Number = 0;

...

printf("Enter a number: ");

cin >> Number;

...

printf("Square of %f is %f\n", Number, squareOf_Number(Number));

...

}

Or you can include #include <math.h> and use the function pow(double a, double b) which returns a^b.

C Program To Find GCD?

This function presumes that both parameters are greater than 0.

int gcd(int m, int n)

{ while( m > 0 )

{

if( n > m )

{ int t = m; m = n; n = t; }

m -= n;

}

return n;

}

What is the difference between c plus plus and object code?

Short answer: They're the same.

Due to technical limitations, we on WikiAnswers cannot write C++ in the question field. So we must write "C plus plus." Unfortunately, we're also lazy. So we write "cpp" as an abbreviation.