It is the process of analyzing the run-timebehaviorof the program. It includes analyzing which function takes the longest time, how many times a particular function is called, etc. Some of the profilers are valgrind, etc.
What is the difference between structure and structure using typedef with example?
Consider the following structure:
The name of this type is struct data_t. This means that we must include the struct keyword whenever we declare any instances of the type or declare a pointer to the type:
To remove the verbosity of the otherwise redundant structkeyword, we can use an alias:
To simplify things further, we can combine the alias with the structure's definition:
Note that the _t suffix is conventionally used to denote a user-defined type as opposed to an alias. However, its usage is not consistent. For instance, the wchar_t type is not a type, it is implemented as an alias in the
In C++, the typedef keyword is not required; it is retained purely for backward compatibility with C. Aliases are introduced with the using keyword, never with typedef. We only use typedef when we are explicitly writing code intended for compilation under both C and C++.
Note also that wchar_t (amongst others) is a built-in type in C++, so we don't need to include the C standard library to make use of it, unless we are writing code for C.
You pop elements off of one stack and push them onto the other. This reverses the order of the elements.
while ((element = pop(stack1)) != NULL) push(stack2, element);
How do you remove recursion using stacks?
Using stacks won't remove recursion, they can only re-implement those recursions. In some cases we don't actually need a stack to implement a recursive algorithm, in which case an iterative implementation will typically perform better with little to no cost in additional memory. But if we require a stack in order to implement recursions iteratively, then we pay the cost in terms of additional memory consumption (the "built-in" call stack is fixed-size and exists whether we use it or not). In addition, there may be a performance cost if we cannot determine how much additional memory we need.
As an example, consider the recursive quicksort algorithm:
template<typename T>using iter = std::vector<T>::iterator; template<typename T>void quicksort (iter begin, iter end) {
if (begin<end) {
size_t pivot = partition (begin, end);
quicksort (begin, pivot - 1);
quicksort (pivot + 1, end);
} // end if
}
Note that the partition algorithm is not shown for the sake of brevity. However, it is best implemented as a separate function as its local variables play no part in the recursion.
Being a divide-and-conquer algorithm, this algorithm requires a stack for back-tracking. Here is the iterative equivalent using a stack:
template<typename T>using iter = std::vector<T>::iterator;
template<typename T>void quicksort (iter begin, iter end) {
if (begin<end) {
std::stack<std::pair<iter, iter>> s {};
s.push ({begin, end});
while (s.empty() == false) {
begin = s.top().first();
end = s.top().second();
s.pop();
size_t pivot = partition (begin, end);
if (pivot + 1<end) s.push ({pivot + 1, end});
if (begin<pivot - 1) s.push ({begin, pivot - 1});
} // end while
} // end if
}
Note that the order we push the pairs on at the end of the while loop is the reverse order we wish them to be processed. The order doesn't actually matter, but it ensures both algorithms operate in a consistent manner, with depth-first traversal from left to right.
This implementation is naive because each push allocates new memory for each pair object we push onto the stack, releasing the same memory with each pop. Allocating and releasing system memory on a per-element basis like this is highly inefficient, so it's highly unlikely that this version will perform any better than the recursive algorithm.
However, the quicksort algorithm guarantees that there can never be more elements on the stack than there are elements in the initial range, so we can improve performance significantly by reserving sufficient memory in advance:
template<typename T>using iter = std::vector<T>::iterator;
template<typename T>void quicksort (iter begin, iter end) {
if (begin<end) {
std::vector<std::pair<iter, iter>> v {};
v.reserve (end - begin);
v.emplace_back (begin, end);
while (v.empty() == false) {
begin = v.back().first();
end = v.back().second();
v.pop_back();
size_t pivot = partition (begin, end);
if (begin < pivot - 1) v.emplace_back (begin, pivot - 1);
if (pivot + 1 < end) v.emplace_back (pivot + 1, end);
} // end while
} // end if
}
Note that in this implementation we use a vector rather than a stack, however all pops and pushes (implemented as emplace_back operations) occur at the back of the vector where the unused elements are, and that's precisely how an efficient stack should be implemented. As a result, this version will perform significantly better than the previous version and should perform at least as well as the recursive implementation if not better. The only significant cost is the cost of reserving memory in the vector.
What is the inverse of a conditional statement?
The statement formed when you negate the hypothesis and conclusion of a conditional statement.
For Example: If you had enough sleep, then you did well on the test.
The inverse will be: If you didn't have enough sleep, then you didn't do well on the test.
STL is an abbreviation for many different things. Most commonly, when one uses STL, they are referring to St. Louis, Missouri.
What is the Main purpose of complex.h header file in c plus plus?
The complex header implements complex numbers. Complex numbers are represented by the expression a + bi where a and b are real numbers and i is an imaginary unit that satisfies the constant expression i squared = -1.
Complex numbers allow imaginary solutions to expressions that have no actual solution. For instance, (x + 1) squared = -9 has no real solution, but does have two imaginary solutions when x = (a + bi), where a is -1 and b can be 3 or -3.
Note that library headers with an h extension are pre-standard headers. After standardisation, all library headers dropped the h extension including the complex header. Older compilers may still provide both versions of a library header, but in this day and age you should always use the standardised headers (no extension).
#include<complex.h> // non-standard
#include<complex> // standardised
How do you make a UIPickerView that plays sounds?
The UIPickerView doesn't actually play the sounds; you do that with a hidden media control. When you click the control button, you examine the selected element in the list and load the associated sound file into the media control, which then plays the file. There are various ways of doing it, but one of the simplest methods is to use two parallel arrays, one containing the titles (which you load into the list), the other containing the paths to the sound files. Both arrays being of type std::string, of course. Thus element 9 in the titles array maps to element 9 in the sound files array. Alternatively, use std::pair objects (where each element in the pair is a std::string) to associate each title with its sound file.
What is a user defined manipulator in c plus plus?
A user-defined manipulator is a function which can be passed as an argument to the stream insertion or extraction operator overloads. For example, the output stream insertion operator has the following overload:
std::ostream& operator<< (std::ostream& st, std::ostream& (*func) (std::ostream&));
The second argument is the function pointer, with the following signature:
std::ostream& (*func) (std::ostream&)
Any function that matches this signature can be used as a manipulator. For instance, the following user-defined manipulator does exactly the same job as the std::endl manipulator:
std::ostream& my_manipulator (std::ostream& os)
{
return os << '\n' << std::flush;
}
Example usage:
std::cout << "Hello world!" << my_manipulator;
You can, of course, provide your own implementations to perform any type of manipulation. For example, suppose you want a manipulator that inserts an elipses into an output stream:
std::ostream& elipses (std::ostream& os)
{
return os << "...";
}
Example usage:
std::cout << "Hello" << elipses << "world!" << my_manipulator;
Output:
Hello...world!
What is callback function in c?
In computer programming, a callback is executable code that is passed as an argument to other code. It allows a lower-level software layer to call a function defined in a higher-level layer. Usually, the higher-level code starts by calling a function within the lower-level code passing to it a pointer or handle to another function. While the lower-level function executes, it may call the passed-in function any number of times to perform some subtask. In another scenario, the lower-level function registers the passed-in function as a handler that is to be called asynchronously by the lower-level at a later time in reaction to something. A callback can be used as a simpler alternative to polymorphism and generic programming, in that the exact behavior of a function can be dynamically determined by passing different (yet compatible) function pointers or handles to the lower-level function. This can be a very powerful technique for code reuse. Callback functions separate the caller from the callee, the caller doesn't care who the callee is For complete understanding we need to know about Function pointers in c. check the link below
C plus plus program to insert an element using binary tree?
The algorithm for inserting into a binary tree is fairly straightforward. Start by passing the element to the root node of the tree. If there is no root, the new element becomes the root and you're done. Whenever a node receives a new element, it compares the element's value with its own value. If the new element is lower in value, pass the element to the left node otherwise pass it to the right node. If there is no node in that position, the new element becomes that node. In this way, the node's themselves decide where new elements are placed.
In order to achieve this you need a node that encapsulates some data. Typically the data is a template parameter but for the sake of simplicity let us assume the data is an unsigned integer. We'll also need pointers to the left and right nodes. We'll use the default constructor to initialise the data and pointers. we'll also need an insertion method. Thus our node class looks like this:
class node
{
private:
node* left;
node* right;
unsigned data;
public:
node(unsigned value): left(NULL), right(NULL), data(value) {}
void insert(unsigned value);
};
The insert method will be implemented as follows:
void node::insert(unsigned value)
{
if (value<data)
{
if (left) left->insert(value); else left = new node(value);
}
else
{
if (right) right->insert(value); else right = new node(value);
}
}
That's all there is to it. All you need now is a pointer to the root which will initially be NULL. When you come to insert a value and the root is NULL, create a new node and assign it to the root pointer, otherwise call root->insert(value); and let the tree sort itself out.
TCDEF.exe probably relates to Borland Turbo C (TC). I can't find any info on the file itself, other than that some people using TC seem to have problems locating the file during compilation. That's usually a sign of a bad install or (more likely) the presence of malware. Given the lack of information I suspect TCDEV.exe is not a legitimate part of TC.
What are the types of end users?
There are two types of End user
1.Native User
2.Sophisticated User (Technical User)
Which is preffered in C malloc or new why?
C does not have a new operator, so we must use the malloc function.
In C++ we prefer the new operator over malloc. The new operator not only allocates memory to an object, it invokes that object's constructor, thus ensuring correct initialisation of the object, thus establishing the object's invariant (if it has one). If construction fails for any reason, an exception will be thrown and no object will be instantiated. If the class designer has made correct use of resource acquisition is initialisation(RAII), any resources consumed by the constructor prior to throwing the exception will be automatically returned to the system, thus ensuring no resource leaks occur.
The sole purpose of malloc is to allocate memory and nothing more. If the allocation fails, a null pointer is returned, otherwise the start address of the allocation is returned. However, the memory is left in an uninitialised state even if the object has a constructor. Moreover, neither malloc, calloc nor realloc will throw exceptions so they are unsuitable for enabling RAII. The only reason they exist at all in C++ is simply for the sake of backward compatibility with C code which cannot use the new operator (since it does not exist in C).
How do you program reverse letters using arrays in C plus plus?
char * RevString( char * str )
{
char * dup = strdup( str );
size_t len = strlen( str );
int x = 0;
int y = len;
while( x str[ x++ ] = dup[ --y ]; free( dup ); return( str ); } Note that you don't actually need this function since the standard built-in strrev() function reverses strings more efficiently than this.
How do you run dev-c plus plus on Windows 8?
I don't run either DevCPP or Windows 8. However, I did some checking around and found the following answers. The related links to them are provided beneath this answer.
1) Run DevCPP in Windows XP Compatibility Mode: right-click the icon and select "Run in earlier versions of Windows"
2) Update DevCPP (see the SourceForge related link below)
The problem seems to be that you're running an outdated version of MinGW GCC.
If neither of the above answers help, try a Web search for devcpp "windows 8" or devc++ "windows 8".
Also, keep in mind that Windows 8 is still in beta development, so expect errors and problems to crop up. I'd recommend sticking with earlier Windows versions until at LEAST a service pack gets released if you continue to encounter technical difficulties and are unable to find answers on the Web.
Write a program to create object without name?
You cannot create an object without a name. The name identifies the object. If you really mean anonymous classes, then the following is an example of an anonymous class (a class with no identifier):
typedef struct
{
unsigned x;
unsigned y;
} POINT;
There are some restrictions with regards anonymous classes:
This is not a question, it is an assignment.
class Geo {
public:
virtual double area (void) const = 0;
virtual ~Geo (void) {}
// ...
};
class Rect : public Geo {
private:
double m_width;
double m_height;
public:
Rect (double width, double height): m_width (width), m_height (height) {}
double area (void) const override { return m_width * m_height; }
~Rect (void) override {};
// ...
};
class Sqr : public Rect {
public:
Sqr (double width): Rect {width, width} {}
~Sqr (void) override {}
// ...
};
What is unreachable code in c plus plus?
Unreachable code is code that can never execute. It usually happens when you have a logic error in your code, such as when an if condition always evaluates true (or false). For example:
int foo(int& x)
{
if( &x == NULL ) // always evaluates false...
{
// Unreachable code:
std::err<<"int foo(int&) : argument int& is a NULL reference"<<std::endl;
return(-1);
}
return(0);
}
In the above example, the entire if() statement is redundant because the argument, x, is a reference. In C++, references can never be NULL, so the if statement can never evaluate true. Furthermore, in this particular example, the entire function can be said to be redundant (but not unreachable), simply because it serves no purpose. It will always return zero.