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 arranging characters in alphabetical order?

Arranging characters in alphabetical order is exactly what it sounds like. You must arrange characters in the order that they appear alphabetically.

What is the flowchart for finding modulus of a number?

The modulus of a number is the units digit of that number in the base of the modulus. For example, counting to 10, modulus 3, we get... 0 0

1 1

2 2

3 0

4 1

5 2

6 0

7 1

8 2

9 0

10 1 The calculate the modulus of a number, subtract the (integer of the number divided by the modulus) times the modulus. As an expression, this is... Xmod Y = X - integer (X / Y) * Y Note: This works also for negative numbers. -3 mod 5 is 2. Check it, if you want. The result will be correct so long as the integer trunction is towards zero, i.e. the integer of -1.3 is -1, not -2. Most compilers do this correctly. If you are using a compiler such as C, the modulus operator (%) will do this for you... int a;

a = 7 % 3; /* 7 mod 3 is 1 *.

What sort of stuff does McDonaldization do?

McDonaldization is a term that describes the the control of a process. In the case of McDonalds, it means the process of making a hamburger, is more controlled and everything comes out the same.

How do you write a program to find the kinetic energy in C?

The equation to find kinetic energy is based on knowing the mass and velocity of the object in question. Specifically, the equation is as follows:

KE = ½ mv2

In C, this equation can be specified as:

v*v*m/2

...since it's half of the mass multiplied by the square of the velocity.

If you haven't written a C program before, see the related links for a solid C tutorial, or try a Web search for c tutorial. Also included in the related links are pages about kinetic energy formulae.

How to write a function to reverse an array without using square brackets in the function?

void reverse (char* str) {

char *left, *right, temp;

left = right = str;

while (*right) ++right;

--right;

while (left < right) {

temp = *left;

*left = *right;

*right = temp;

++left;

--right;

}

}

How do you write a c program that sums a sequence of integers?

The simplest way is to store the sequence in an array, then pass the array to the following function:

int sum (int* a, int size) {

int s = 0;

for (int i=0; i<size; ++i) s += a[i];

return s;

}

Example usage:

int x[5] = {1, 2, 3, 4, 5};

int s = sum (x, 5);

assert (s == 15);

Explain goto and return in c?

A return statement is used to transfer the program control flow to the function that has called the current function under execution. If the function is main, then the program returns the control flow to the operating system. The syntax for return statement is:

return return-type;


A goto statement is used to transfer the control flow to a particular labelled statement, not necessarily back to the calling program. There are somerestrictionson using a goto statement. For eg: the goto statement should not skip any variable declarations. The use of goto statement is usually considered as a bad programming practice. The syntax for goto statement is:


goto label_name;

..

..

label_name: statements;

What are the various applications of linear search in real time?

Linear search is necessary when we must search unordered sets. Linear search times across huge sets can be improved significantly by dividing the set amongst two or more threads that can execute on independent CPU cores.

How to Reverse a string using pointers in C?

#include<stdio.h>

#include<conio.h>

#include<string.h>

void main()

{

char str1[]="ravi kant yadav";

char str2[20],*p1,*p2;

clrscr();

p1=str1+strlen(str1)-1; //Make p1 point to end of str1.

p2=str2;

while(p1>=str1)

*p2++=*p1--;

*p2='\0';

printf("Original string=%s. Reversed String=%s",str1,str2);

getch();

}

What is virtual inheritance?

Virtual inheritance is used in multiple inheritance hierarchies whenever two or more classes inherit from the same base class. For example, consider the following minimal example:

struct A {int x;};

struct B : A {};

struct C : A {};

struct D : B, C {};

Here, A is a common base class of both B and C, thus B::A and C::A are independent instances of A. However, D inherits from both B and C thus indirectly inherits both B::A and C::A. This introduces an ambiguity when implicitly referring to A from D, as in the following example:

D d; d.x = 42; // error: ambiguous

When the compiler sees this it won't know whether we are referring to B::A.x or C::A.x, thus we must be explicit when referring to A via D:

d.B::x = 42; // ok

The problem with this is that we still have two separate instances of x so unless we are extremely careful about which x we are referring to we can easily end up with two different values for x with no way of knowing which was the correct value with respect to D.

What we really need is for B and C to share the same instance of A and we achieve that through virtual inheritance:

struct A {int x;};

struct B : virtual A {};

struct C : virtual A {};

struct D : B, C {};

D d;

d.x = 42; // ok

Note that d.x can be referred to as d::A.x, d::B::A.x or d::C::A.x because they all refer to the same instance of x, thus the ambiguity is eliminated. In effect, the most-derived class in the hierarchy (D) is now a direct descendant of A rather than an indirect descendant of both B::A and C::A.

Note also that the virtual keyword has no effect on independent instances of either B or C because they then become the most-derived classes within their own hierarchy and therefore behave exactly as they would had the virtual keyword been omitted. The virtual keyword only comes into play when we derive from a class with a virtual base.

It is also possible to have a base class that is both virtual and non-virtual in the same hierarchy:

struct A {int x;};

struct B : virtual A {};

struct C : virtual A {};

struct D: A {}

struct E : B, C, D {};

Here, A is a virtual base of both B and C, as before, but not of D. Thus E::A implicitly refers to the virtual A while E::D::A must be explicitly referred to as E::D::A because it is a separate instance. Such classes are best avoided, but if we don't have access to the source code we sometimes don't have a choice in the matter.

However, if a base class holds no data it really doesn't matter whether it is declared virtual or not because a class that has no data consumes just one byte regardless of how many instances there are.

C program to find the largest digit of a number?

#include<stdio.h>

#include<conio.h>

main()

{

int n,max=0,rem;

printf("\n enter a number");

scanf("%d",&n);

while(n!=0)

{

rem=n%10;

n=n/10;

if(rem>max)

{

max=rem:

}}

printf("\n the largest digit is: %d",max);

getch();

}

What is a operator in access?

It is any of the operators used to compare things to see if they are equal or greater than to less than etc. So ones like > < = are all comparison operators.

Write a algorithm to print even number in C programming language?

#include<stdio.h>

#include<conio.h>

void main()

{

int n;

clrscr();

printf("\n enter the number:");

scanf("%d",&n);

if(n%2==0)

printf("\n the number is even");

getch();

}

What is meant by void abcint?

void abc(int); is a function declaration. The declared function has no return value, is named abc and accepts one integer argument by value.

What type of a variable is used to indirectly return multiple results by a function?

To return multiple values of the same type, return an array. If the values are different types, return a tuple or data structure. To return values indirectly, return a pointer to the results (arrays implicitly convert to pointers, but tuples and data structures do not). A returned pointer must never refer to a local variable of the returning function; upon return, those variables will cease to exist, resulting in undefined behaviour. To avoid this, the caller may provide a user-defined storage location via an output argument, or the function may allocate the return values on the free store (the heap).

Can you use a sequential search on an unsorted array?

Sequential search is the only way to search an unsorted array unless you resort to a multi-threaded parallel search where all threads concurrently search a portion of the array sequentially.

How many IDE devices can you have?

Short answer: Four

A much more precise answer: The IDE standard allows for two devices to share a single IDE channel. The most common configuration is for there to be two IDE channels on the motherboard, allowing for a total of four devices. It is possible however, to add more IDE channels, usually in the form of PCI add-on IDE controller cards and have literally dozens of IDE devices in a single computer system.

What is dynamic queue?

Dynamic queue is one that can grow to allow for more entries.

àA static queue has a fixed number of slots and once they are full no more entries can be supported until one entry leaves the queue.