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

Why array indexes starts from zero in c-language?

In order to provide modulo (%) facilities as far as mathematics and logic is concern.

for instance , if we have no of employees in our list say 1545 and if we want to accommodate it within small and effective range then by using % we can do it easily....

we can arrange it in the range within Array with maximum index 14 (0,1,2,.....14).

And 0,15,30,45......1545 will belongs to same category say index no 0.

Think if 0 is not included into index then where we would store 0,15,30,45....1530,1545 .

From a technical standpoint, you need to understand that an array is basically just the starting address of a chunk of memory. The "index" of the array is actually an address offset. So the value at the 0th position would be stored at the address of the array plus zero. The value at the 1st position would be stored at the address plus one, and so on.

How do you write a recursive function for summing ints?

for example "sumNums(12345)" would sum 1+2+3+4+5.

the recursive code is just really confusing me.

unsigned sumDigits (unsigned n)

{

. . if (n<10) return n;

. . else return n%10 + sumDigits (n/10);

}

Program to check whether the given number is an Armstrong number?

<html>

<head>

<Script Language="JavaScript">

var a,n,b=0,t;

n=parseInt(window.prompt("enter n","0"));

t=n;

while(n>0)

{

a=n%10;

b=b+a*a*a;

n=n/10;

}

if(b==t)

{

document.writeln("Armstrong no");

}

else

{

document.writeln("Not an Armstrong no");

}

</script>

</head>

</html>

What do you normally create when you want to run a function in the background while processing other things?

You normally create a thread when you want to run a function in the background while processing other things.

1's complement of 1000?

Ones complement simply switches the state of all the bits (0s becomes 1s and 1s becomes 0s). Assuming 1000 is binary (for decimal 8), the 1's complement would be 0111. But if 1000 is really decimal one thousand, the binary equivalent would 1111101000, thus the ones complement would be 0000010111.

Ones complement was originally used to represent signed integers. To flip the sign, all bits were flipped and the most-significant bit denoted the sign (0 for positive, 1 for negative). The problem with one's complement is that we end with two representations for the value zero: 00000000 and 11111111 in 8-bit notation. To eliminate this, most modern systems now use twos complement, which is ones complement plus one. Thus 00000000 is 11111111 + 00000001 which is 00000000.

Note that ones complement notation means that an 8-bit value has a valid range of -127 through +127 (with two representations for zero) while twos complement gives us a range of -128 through +127. Signed integer notation is also system-dependent, hence the reason why a char data type in C only has a guaranteed range of at least -127 through +127 across all implementations. For that reason it is not safe to assume that -128 has a valid representation in 8-bit signed notation across all implementations.

Where is it possible to buy an Obagi C?

The best place to purchase an Obagi C online is lovelyskin because they are currently offering a 20 percent discount. There are also authorized Obagi dealers that you can find on their website through the find a dealer option.

C program for counting sort?

#include<stdio.h>

#include<conio.h>

void main()

{

clrscr();

int i,j,m,a[20],b[20],c[20],max;

printf("enter no of elements");

scanf("%d",&m);

printf("enter elements");

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

{

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

}

max=a[i];

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

{

if(max<a[i])

{

max=a[i];

}

}

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

{

c[i]=0;

}

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

{

c[a[j]]=c[a[j]]+1;

}

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

{

c[i]=c[i]+c[i-1];

}

for(j=m;j>=1;j--)

{

b[c[a[j]]]=a[j];

c[a[j]]=c[a[j]]-1;

}

printf("AFTER SORTING");

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

{

printf("%d",b[i]);

}

getch();

}

What is a Structured Settlement?

A structured settlement is a financial or insurance arrangement, including periodic payments, that a claimant accepts to resolve a personal injury tort claim or to compromise a statutory periodic payment obligation. Structured settlements were first utilized in Canada and the United States during the 1970s as an alternative to lump sum settlements. Structured settlements are now part of the statutory tort law of several common law countries including Australia, Canada, England and the United States. Although some uniformity exists, each of these countries has its own definitions, rules and standards for structured settlements. Structured settlements may include income tax and spendthrift requirements as well as benefits. Structured settlement payments are sometimes called "periodic payments." A structured settlement incorporated into a trial judgment is called a "periodic payment judgment."

How do virtual functions differ from pure virtual functions?

Virtual functions is a function that can be overridden in inheriting class with the same signature (function name, parameters number, parameters types and return type);

Pure virtual function is function that does not have implementation and if class has pure virtual function is called abstract. It is not possible to instantiate that class. Some other class must inherit it and define the body for it (implement). In other words class only have function prototype/declaration(signature) and no definition(implementation).

What is declaration syntax of an array?

In what language?

c and c++

a 5 x 5 array of Int

int nMultiIntArray[5][5];

Answer:

in java

int array[][]=new int[5][5];

in vb

dim array(5,5) as Integer

What does num stand for'?

here it is :D im starrystar33 if you want to know nowummeow haha

What is the C plus plus programs to implement the stack ADT using a singly linked list?

#include<iostream>

#include<time.h>

#include<forward_list>

int main()

{

// seed random number generator

srand ((unsigned) time(NULL));

// a forward_list is a singly-linked list

std::forward_list<int> stack;

// push 10 integers onto stack

for (int loop=0; loop<10; ++loop)

{

int num=rand();

std::cout<<"Pushing "<<num<<std::endl;

stack.push_front (num);

}

// pop all integers

while (!stack.empty())

{

std::cout<<"Popping "<<stack.front()<<std::endl;

stack.pop_front();

}

}

What is the primary value in using virtual functions within C plus plus?

Virtual methods are member methods of a base class that can be overridden by derived classes. Classes that can act as base classes should contain all the functionality that is common to all their derived classes. However, the derived classes may need to alter that functionality in some way by overriding the methods in the base class.

While this is fine when we actually hold pointers or references to a derived object, what happens when we hold pointers or references to the base class of a derived object? We cannot call the overridden methods explicitly unless we expose the runtime class of the derived object, which would incur an unacceptable processing overhead.

Virtual methods allow us to get around this problem in a more elegant fashion. By declaring a method as virtual, calling the method implicitly on a base class will automatically and explicitly call the most-derived implementation in the class hierarchy. If no override exists, the base class method is called explicitly.

While this mechanism incurs a memory penalty in creating the v-table (virtual table), the bulk of that cost is paid with the first virtual method declared. Subsequent methods add very little overhead, so it is not uncommon for programmers to declare all methods virtual. However, if there is at least one virtual method declared, the class destructor must also be declared virtual. Thereafter, you should only declare other methods to be virtual if there is an actual need to do so. After all, there's no point in consuming more memory than is actually required.

Sometimes it is not possible for a base class to provide the implementation for a virtual method, In this case the method should be declared pure-virtual. The same rules apply as for virtual functions, however you can no longer instantiate objects from the base class itself -- it becomes an abstract class -- so you must derive from it and you must provide an implementation for all the pure-virtual methods (otherwise it becomes abstract itself).

Abstract classes will generally have few, if any, member variables, and all member methods will generally be declared as pure-virtual. Abstract classes are primarily intended to provide a common interface to their derivatives. The base class can still provide default implementations for pure-virtual methods, however they must be explicitly called. In some cases, a derived class will simply augment the default implementation, rather than override it completely.

Be aware that base classes that are common to derived classes that can be used by multiple inheritance classes will introduce ambiguities. The multiple inheritance class will inherit two or more instances of the common base class, and therefore must be called explicitly from the multiple inheritance class. However, it is possible to remove the ambiguity altogether, by declaring the common base class to be virtual in its immediate derivatives, in which case all derivatives share the same common base class when multiply inherited. Ideally, the common base class should have very little in the way of implementation, and few, if any, member variables.