Tutorial by Examples: c

Include using System.Numerics and add a reference to System.Numerics to the project. using System; using System.Numerics; namespace Euler_25 { class Program { static void Main(string[] args) { BigInteger l1 = 1; BigInteger l2 = 1; ...
RAISERROR function will generate error in the TRY CATCH block: DECLARE @msg nvarchar(50) = 'Here is a problem!' BEGIN TRY print 'First statement'; RAISERROR(@msg, 11, 1); print 'Second statement'; END TRY BEGIN CATCH print 'Error: ' + ERROR_MESSAGE(); END CATCH RAISERROR ...
RAISERROR with severity (second parameter) less or equal to 10 will not throw exception. BEGIN TRY print 'First statement'; RAISERROR( 'Here is a problem!', 10, 15); print 'Second statement'; END TRY BEGIN CATCH print 'Error: ' + ERROR_MESSAGE(); END CATCH After RAISER...
You can re-throw error that you catch in CATCH block using TRHOW statement: DECLARE @msg nvarchar(50) = 'Here is a problem! Area: ''%s'' Line:''%i''' BEGIN TRY print 'First statement'; RAISERROR(@msg, 11, 1, 'TRY BLOCK', 2); print 'Second statement'; END TRY BEGIN CATCH print...
You can throw exception in try catch block: DECLARE @msg nvarchar(50) = 'Here is a problem!' BEGIN TRY print 'First statement'; THROW 51000, @msg, 15; print 'Second statement'; END TRY BEGIN CATCH print 'Error: ' + ERROR_MESSAGE(); THROW; END CATCH Exception with be ...
The following example code is slower than it needs to be : Map<String, String> map = new HashMap<>(); for (String key : map.keySet()) { String value = map.get(key); // Do something with key and value } That is because it requires a map lookup (the get() method) for each ...
The Java Collections Framework provides two related methods for all Collection objects: size() returns the number of entries in a Collection, and isEmpty() method returns true if (and only if) the Collection is empty. Both methods can be used to test for collection emptiness. For example: C...
Let's say you have a library that returns callbacks, for example the fs module in NodeJS: const fs = require("fs"); fs.readFile("/foo.txt", (err, data) => { if(err) throw err; console.log(data); }); We want to convert it to a promise returning API, with bluebird - ...
You can convert a single function with a callback argument to a Promise-returning version with Promise.promisify, so this: const fs = require("fs"); fs.readFile("foo.txt", (err, data) => { if(err) throw err; console.log(data); }); becomes: const promisify = requ...
In order to convert any callback API to promises assuming the promisify and promisifyAll version doesn't fit - you can use the promise constructor. Creating promises generally means specifying when they settle - that means when they move to the fulfilled (completed) or rejected (errored) phase to i...
#include <stdio.h> #include <math.h> #include <omp.h> #define N 1000000 int main() { double sum = 0; double tbegin = omp_get_wtime(); #pragma omp parallel for reduction( +: sum ) for ( int i = 0; i < N; i++ ) { sum += cos( i ); } ...
On a 8 cores Linux machine using GCC version 4.4, the C codes can be compiled and run the following way: $ gcc -std=c99 -O3 -fopenmp loop.c -o loopc -lm $ OMP_NUM_THREADS=1 ./loopc Computing 1000000 cosines and summing them with 1 threads took 0.095832s $ OMP_NUM_THREADS=2 ./loopc Computing 100...
Let f(n) and g(n) be two functions defined on the set of the positive real numbers, c, c1, c2, n0 are positive real constants. Notationf(n) = O(g(n))f(n) = Ω(g(n))f(n) = Θ(g(n))f(n) = o(g(n))f(n) = ω(g(n))Formal definition∃ c > 0, ∃ n0 > 0 : ∀ n ≥ n0, 0 ≤ f(n) ≤ c g(n)∃ c > 0, ∃ n0 > 0 ...
The PHP community has a lot of developers creating lots of code. This means that one library’s PHP code may use the same class name as another library. When both libraries are used in the same namespace, they collide and cause trouble. Namespaces solve this problem. As described in the PHP referenc...
Python changed it's sorting methods to accept a key function. Those functions take a value and return a key which is used to sort the arrays. Old comparison functions used to take two values and return -1, 0 or +1 if the first argument is small, equal or greater than the second argument respectivel...
realloc is conceptually equivalent to malloc + memcpy + free on the other pointer. If the size of the space requested is zero, the behavior of realloc is implementation-defined. This is similar for all memory allocation functions that receive a size parameter of value 0. Such functions may in fact ...
Expression trees represent code in a tree-like data structure, where each node is an expression Expression Trees enables dynamic modification of executable code, the execution of LINQ queries in various databases, and the creation of dynamic queries. You can compile and run code represented by expr...
Several 'insert' functions can "burn" ids. Here is an example, using InnoDB (other Engines may work differently): CREATE TABLE Burn ( id SMALLINT UNSIGNED AUTO_INCREMENT NOT NULL, name VARCHAR(99) NOT NULL, PRIMARY KEY(id), UNIQUE(name) ) ENGINE=InnoDB; IN...
to check if the given path is a directory dirname = '/home/john/python' os.path.isdir(dirname) to check if the given path is a file filename = dirname + 'main.py' os.path.isfile(filename) to check if the given path is symbolic link symlink = dirname + 'some_sym_link' os.path.islink(symli...
A class or struct can have member functions as well as member variables. These functions have syntax mostly similar to standalone functions, and can be defined either inside or outside the class definition; if defined outside the class definition, the function's name is prefixed with the class' nam...

Page 488 of 826