answersLogoWhite

0

📱

C++ Programming

Questions related to the C++ Computer Programming Language. This ranges all the way from K&R C to the most recent ANSI incarnations of C++, including advanced topics such as Object Oriented Design and Programming, Standard Template Library, and Exceptions. C++ has become one of the most popular languages today, and has been used to write all sort of things for nearly all of the modern operating systems and applications." It it a good compromise between speed, advanced power, and complexity.

2,546 Questions

What is 0 plus 2?

The sum of 2 plus 0 plus 0 plus 0 plus 0 plus 0 plus 0 plus 0 plus 0 plus 0 plus 0 plus 0 plus 0 plus 0 plus 0 plus 0 equals 2.

How do you reverse a 5 digit number in c plus plus?

It really does not matter how many digits there are, the principal is exactly the same. The following function is the most efficient way to reverse any whole number in the range -2,147,483,648 to 2,147,483,647, inclusive (assuming a 32-bit integer). To increase the range, create separate functions to cater for 64-bit and 128-bit integers. Converting the number to a string and reversing the string is also an option (see previous answer, below), however it is by far the least efficient method of reversing a whole number.

int RevNum( int num )

{

const int base = 10;

int remain = 0;

int result = 0;

do

{

remain = num % base;

result *= base;

result += remain;

} while( num /= base);

return( result );

}

Previous Answer

This is assuming the number is decimal.

There are several approaches to the problem, depending on the resources you have available or wish to use to solve it.

One way to achieve this is to isolate the digits through modulo division and the remultiply them in the desired order:

rev = ((original % 10) * 10000) + (((original / 10) % 10) * 1000) + (((original / 100) % 10) * 100) + (((original / 1000) % 10) * 10) + (original / 10000);

An alternative that doesn't look so messy:

int temp = original;

int rev = 0;

for (int i=0;i<5;i++)

{

rev = (rev * 10) + (temp % 10);

temp /= 10;

}

If you're employing strings, then another novel way can be used.

#include

#include

#include

char numstring[6];

snprintf(numstring,5,"%d",original);

strrev(numstring);

rev = atoi(numstring);

Note that these are just examples of how it can be achieved. There is no standard function to reverse a decimal number in C or C++, so it's up to you to find or code a solution for yourself.

Explain control instructions in c plus plus?

Control instructions are instructions that alter the flow of execution. In C++ this include if, if-else statements, switch-case statements and the conditional ternary operator (?:), as well as loop structures (for, while, do-while) and procedural goto statements.

What is the difference between the statement a plus plus and plus plus a?

This is used in languages such as C, C++ and Java. The difference is when the statement is executed. If placed before the variable, the increment is done before other operations, otherwise, after them. This is best shown in an example.

a + b++ means to add first, then to increment the variable b.

a + ++b means to increment b first, then to do the addition.

Similarly, in a = b++, b is copied to a, and then increment; while in a = ++b, variable b is incremented before being copied.

A c plus plus programming that accepts an integer from the user and prints the last digit of the entered integer?

To obtain the last whole digit of a number, use the modulo (%) of the number and 10. The modulo evaluates to the remainder after division. Thus 15%10 returns 5 because 15 divided by 10 is 1 remainder 5. Therefore the last digit of any integer, n, is therefore n%10. The same trick can be used to find the last digit for any base, where n is a base 10 integer. Thus n%8 will return the last octal digit, while n%16 will return the last hexadecimal digit.

What is mg plus c plus o2?

The chemical equation representing the reaction of magnesium (Mg) with oxygen (O2) to form magnesium oxide is: 2Mg + O2 → 2MgO The "c" in your equation does not have a clear designation in this context.

What is the difference between static binding and run time binding?

Static binding is where the linker copies the referenced module into the executable image of the program at compilation/link time. The referenced module becomes a part of the executable image. Dynamic binding is where the linker copies only a stub code for the referenced module into the executable image. That stub code loads the referenced module into memory at load/run time. Advantage of static is simplicity. The executable is stand-alone. Disadvantage is the executable image is larger, and if the referenced module changes, then each executable that uses it must be relinked. Another disadvantage is that if you have more than one executable using the module at the same time, you must have multiple copies of it in memory. Advantage of dynamic is reduced size of the executable image and that changing the referenced module does not require relink of the executable. Another advantage is that most operating systems can share the referenced module, meaning that only one copy of the referenced module need exist in all of memory for any number of references to that module, such as from multiple instances of the executable. Disadvantage of dynamic is that the executable is dependent on the shared library at run time. Another disadvantage is that, since the module is shared, it must be reentrant and thread safe, and this is not always done correctly.

What is difference between Bac arrays and DNA arrays?

BAC (Bacterial Artificial Chromosome) arrays are a type of DNA arrays. BAC arrays are usually used for a technique called array CGH (Comparative Genomic Hybridisation) which is used to identify gross deletions or amplifications in DNA (which for example is common in cancer). DNA arrays include BAC arrays but also oligo, cDNA, and promoter arrays. Oligo and cDNA arrays are typically used for gene expression analysis (looking to see how heavily expressed each gene is). Oligo arrays can also be used for SNP (single nucleotide polymorphism) analysis. Promoter arrays are used to identify transcription factor binding sites.

Explain the difference between intermediate inheritance and codominance?

In codominance, neither phenotype is recessive. Instead, the heterozygous individual expresses bothphenotypes. Intermediate inheritance is when neither allele is dominant to another, but a mixture is produced in the 2 alleles present. A mixed phenotype is given that is between the two parents phenotype .e.g Red flowers (RR) crossed with white flowers (WW) produces pink flowers (RW).

Definition of sample profiling?

Sample profiling involves analyzing a subset of the data (sample) to gain insights into the characteristics and behavior of the entire population. This technique is commonly used in market research, data analysis, and data mining to make inferences and predictions about a larger group based on the sample data. It helps to understand the key attributes, trends, and patterns to make informed decisions.

Main deffrent between c and cpp?

The main difference between c and c++ is the concept of 'Object Oriented Programming' (OOPS).

Thus c does not have the benefits of oops like:

1. abstraction

2. encapsulation

3. inheritance

4. polymorphism etc.

What is the difference between traversal and search?

Traversal simply means moving from one node to the next. Generally one searches by traversing the list, comparing each node's data with a given datum, either to return a pointer to a single matching node, or to return a list of matching nodes (copied from the list being searched), or simply to collect data about the matching nodes (such as a count of all the matching nodes).

Write a program using while loop?

//program to find the factorial value f any number using while loop

#include<stdio.h>

void main()

{

int i,n,fact=1;

printf("Enter the number\n");

scanf("%d",&n);

i=n;

while (i>=1)

{

fact=fact*i;

i--;

}

printf("The factorial value=%d",fact);

}

the above is a program for calculating tha factorial value of any number which is entered by the user

What are the advantages of the new operator?

The new operator in C++ works in a similar manner to malloc in C, allocating memory from the heap (the free store). However, unlike malloc which returns a void* pointer to uninitialised memory, the new operator returns a pointer of the given type and invokes the appropriate constructor for that type. Moreover, every class of object can overload its new operator to allow construction within memory that has been allocated in advance. That memory is typically allocated through a resource handle (known as an allocator), however we can also override the global new operator if we need to provide our own memory management.

We can still use malloc in C++, however it has no advantages over the new operator and is best avoided in the interests of consistency and, more importantly, type safety. In practice we rarely use the new operator unless we are actually designing our own resource handles or low-level memory allocators. The standard library already provides highly efficient resource handles for the vast majority of our everyday needs, so it is rarely necessary to design our own. Nevertheless, the facility exists for those (very) rare occasions where we really do require "raw" memory.

What is parameters in C plus plus?

Parameters are the formal arguments of a function, as defined by the function. When you pass arguments to a function, those arguments are assigned to the function's parameters, either by value or by reference, depending on how the parameters are declared in the function. The following example explains both:

void foo( int param )

{

// param is a by value parameter, which is a copy of the argument passed to it.

}

void bar( int& param )

{

// param is a reference parameter, which references the argument passed to it.

}

int main()

{

int arg = 100;

foo( arg );

bar( arg );

return( 0 );

}

Note that passing a pointer is the same as passing an int by value: the pointer's value is passed to the function, not the pointer itself. To pass a pointer by reference, you must pass a pointer to pointer and the function's parameter must accept a pointer to pointer.

WAP in c plus plus to implement linked list?

#include<iostream>

#include<list>

int main()

{

// the linked list (of integers)

std::list<int> List;

// insertions:

List.push_back (42);

List.push_back (99);

List.push_back (60);

List.push_front (55);

// point to first node

std::list<int>::iterator n = List.begin();

// advance to next node

++n;

// insert in front of node n

list.insert (n, 33);

// print list:

for (auto node : List) std::cout << node << std::endl;

}

What is mean by resident monitor?

A Resident monitor (1950s-1970s) was a piece of software that was an integral part of a general-use punch card computer.

additional ;

Its main function is to control transferring of Computer from one job to another job