background preloader

Technical

Facebook Twitter

Is not available. C++ Design Pattern: What is a Design Pattern? Memory Snapshot for a Process. In-depth memory layout is specific to both the CPU architecture and the OS itself. I'm going to describe how a process sees its own memory share during execution. Memory Layout from a process perspective When a program is executed it is read into memory* where it resides until termination. The code allocates a number of special purpose memory blocks for different data types. In order to prove that things work this way (on many systems anyway) I wrote a C program, mem_sequence.c, that allocates 5 types of data, finds their location the (virtual) memory address, sorts them in descending order and then displays presenting a similar output to the table above. mem_sequence.c is tested on Linux, FreeBSD, MacOS X, WinXP and DOS.

This is how you use mem_sequence: $ gcc mem_sequence.c -o mem_sequence$ . Let's analyze it:The code (5) and constants (4) fall into the readable and executable (non-writable!) It works, great news, but it works differently on different x86 based Operating Systems. 100 C Interview Questions & C FAQs. Tree traversal. Types[edit] Pre-order: F, B, A, D, C, E, G, I, H In-order: A, B, C, D, E, F, G, H, I Post-order: A, C, E, D, B, H, I, G, F Level-order: F, B, G, A, D, I, C, E, H Compared to linear data structures like linked lists and one-dimensional arrays, which have a canonical method of traversal (namely in linear order), tree structures can be traversed in many different ways. Starting at the root of a binary tree, there are three main steps that can be performed and the order in which they are performed defines the traversal type.

These steps (in no particular order) are: performing an action on the current node (referred to as "visiting" the node), traversing to the left child node, and traversing to the right child node. The name given to a particular style of traversal comes from the order in which nodes are visited. For the purpose of illustration, it is assumed that left nodes always have priority over right nodes. Depth-first[edit] Pre-order[edit] In-order (symmetric)[edit] Post-order[edit] etc. C++ casting operators. Converts between types using a combination of explicit and implicit conversions.

[edit] Syntax Returns a value of type new_type. [edit] Explanation 1) When the C-style cast expression is encountered, the compiler attempts the following cast expressions, in this order: a) const_cast<new_type>(expression) b) static_cast<new_type>(expression), with extensions: pointer or reference to a derived class is additionally allowed to be cast to pointer or reference to unambiguous base class (and vice versa) even if the base class is inaccessible (that is, this cast ignores the private inheritance specifier). C) static_cast (with extensions) followed by const_cast d) reinterpret_cast<new_type>(expression) e) reinterpret_cast followed by const_cast The first choice that satisfies the requirements of the respective cast operator is selected, even if it cannot be compiled (see example).

In addition, C-style cast notation is allowed to cast from, to, and between pointers to incomplete class type. [edit] Example.

VTABLE

Showthread. Complex Function pointers. Floating Point Numbers. By Jeff Bezanson Numbers are surely the most prevalent kind of data in computer programs. They are so fundamental that people don't spend much time talking about them—surely everybody knows how to use numbers in their programs. Well, one of the wonderful things about programming is that nearly everywhere you look, you find more than meets the eye. Most programmers have heard or observed one strange thing or another about floating point numbers.

For example, we often discover that floating point numbers that look the same do not necessarily satisfy C's "==" test. New programmers are usually taught never to use == for floating point numbers for this reason. Occasionally we run into other exceptional cases, for instance mathematically sound formulae which, when implemented using floating point, produce seemingly random or disappointingly inaccurate results. What is going on? Floating point numbers are the exact opposite of integers with respect to accuracy and precision.

Debbugger Writing