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.
#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();
}
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 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."
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
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();
}
}
Write a preprocessor directive to accomplish Define symbolic constant YES to have the value 1?
I'm not exactly sure that this is a question, but here you are:
#define YES 1
A Proof, 2-column proofs for geometry are common.
Is it every c program must have atleast one user defined function?
Yes, the minimum is the following:
int main (void) { return 0; }
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.
What is NULL array in C Language?
There is no "NULL array" as such, you may take a pointer to an array and set it to NULL (binary 0) e.g.
int* foo; // Declare a pointer
foo = malloc( 40 * sizeof(int)); //Allocate an array of 40 integers pointed to by "foo"
foo = NULL; //Set the pointer to NULL, if you're using a garbage collector this should trigger an automatic free() of the memory allocated to the array. If you are NOT using a garbage collector (which is more common in C) this line is a memory leak.
How do you use union in embedded system C programming?
All members of a union are assigned the same memory address. As such, assigning to any member of a union changes the value of all members in that union.
The total number of bytes allocated to a union is equal to the length of the largest member of that union. Where the members differ in length, assigning to a member will completely overwrite all the smaller members but will only partially overwrite any larger members.
After assigning a value to a union member, that member is said to be "active". The active member remains active until a value is assigned to another member. However, a union does not keep track of which member is currently active; the onus is entirely upon the programmer to ensure the correct member is accessed.
In some cases, keeping track of the active member is not necessary. For instance, consider the following union:
union u {
int i;
char c[sizeof(int)];
};
This union has two members, both of which are the same length, sizeof(int). We can read and write integer values through the u::i member just as we can any ordinary integer, however the u::c member allows us to read and write the individual bytes within the integer. Since both members are integral types, there is no need to keep track of which member is currently active; it simply provides two methods of accessing the same memory. Thus if we need to access a multi-byte value at the byte level, a union provides the most intuitive method of achieving it without resorting to type casting a pointer.
Where members differ in size, we often need to keep track of which member is active. One method of achieving this is by embedding the union in a struct along with an enum member to keep track of the active member of the union:
typedef enum a_t {num, arr} a;
union u {
int number;
int* array;
};
struct s {
u data;
a active;
};
In the above example, we can choose to store a single value in s::u::number or we can choose to store multiple values in the memory pointed to by s::u::array. However, if we store a value in s::u::number and then attempted to dereference the s::u::array pointer, we incur undefined behaviour because a) an int and a pointer (to any type) are not guaranteed to be the same length and b) the number may not contain a valid address.
Therefore it is important that whenever we write to s::u we update s::a to reflect which member was written to and we must read s::a before accessing s::u. In addition, we must be sure to release any resources currently allocated to the s::u::array before assigning a new value to s::u.
In this example we don't actually gain any benefit by using a union because we end up using just a much memory as we would if the two members were allocated to separate addresses, because of the need to keep track of the active member. However, if the union has three or more members, we begin to save memory because all the "inactive" members cost nothing.
What are the limiting assumptions of C-V-P analysis?
I am interpreting the question as above as Cost Volume Profit(CVP) analysis. If this is not so, my answer below will not be correct. First of all, CVP is used in Finance or Accounting, to describe the behaviour of cost, revenue and profit. Other disciplines also use this analysis, and will be called a different name. In Business Management, it's often called Break Even Analysis. One of limiting assumptions of CVP analysis is the assumption of a linear function of the variable cost and total cost. This means that the cost of a business will increase in a proportional manner, if I make 2 units of output, the cost is 4, if I make 4 units of output, the cost is 8. While this may be possible in theory, it reality, it's not so. If we assume that the cost is linear, the Variable Cost and the Total Cost will be a straight line. In reality, the variable cost doesn't increase in along a straight line. ( not so perfect in reality ). Apart from that, the CVP analysis also assumes that there are no stocks present. The analysis just shows that goods are sold and the company has no stocks kept. Although these can be seen as a limiting assumptions of the CVP analysis, it's important to understand it provides an understanding to students who are new to it. In Economics, the CVP analysis is more complicated, with the variable cost and the total cost function a curve. This means that the cost will fall initially and then increase later. Apart from that in other Ecnomics, costs are considered with the short run and long run perspective. Costs may not be the same in short run and long run.
What was the result of trinity test?
Trinity was the first test of technology for a nuclear weapon. It was conducted by the United States on July 16, 1945, at a location 35 miles (56 km) southeast of Socorro, New Mexico, on what is now White Sands Missile Range, headquartered near Alamogordo. Trinity was a test of an implosion-design plutonium bomb. The Fat Man bomb, using the same conceptual design, was dropped on Nagasaki, Japan, on August 9th. The Trinity detonation was equivalent to the explosion of around 20 kilotons of TNT and is usually considered the beginning of the Atomic Age.
Is a global variable a non-local variable?
True, a variable cannot be both global and local. But if a global and a local variable share the same name, the local one will hide the global.
What is the difference between instruction registers and instruction pointer?
instruction register is used to store the next instruction to be executed.
instruction pointer is used to store the address of the next instruction to be executed.
What does a signed data type mean?
signed: its value can be less than zero
unsigned: its value cannot be less than zero
example:
16 bit signed: -32768 .. 32767
16 bit unsigned: 0 .. 65535
A binary tree with 20 nodes has null branches equals?
A binary tree with n nodes has exactly n+1 null nodes or Null Branches.
so answer is 21.
MOHAMMAD SAJID