Tutorial by Examples: an

This is an example of dereferencing a NULL pointer, causing undefined behavior. int * pointer = NULL; int value = *pointer; /* Dereferencing happens here */ A NULL pointer is guaranteed by the C standard to compare unequal to any pointer to a valid object, and dereferencing it invokes undefined...
int i = 42; i = i++; /* Assignment changes variable, post-increment as well */ int a = i++ + i--; Code like this often leads to speculations about the "resulting value" of i. Rather than specifying an outcome, however, the C standards specify that evaluating such an expression produc...
alias word='command' Invoking word will run command. Any arguments supplied to the alias are simply appended to the target of the alias: alias myAlias='some command --with --options' myAlias foo bar baz The shell will then execute: some command --with --options foo bar baz To include mul...
println! (and its sibling, print!) provides a convenient mechanism for producing and printing text that contains dynamic data, similar to the printf family of functions found in many other languages. Its first argument is a format string, which dictates how the other arguments should be printed as t...
Composition provides an alternative to inheritance. A struct may include another type by name in its declaration: type Request struct { Resource string } type AuthenticatedRequest struct { Request Username, Password string } In the example above, AuthenticatedRequest will con...
In order to test the beginning and ending of a given string in Python, one can use the methods str.startswith() and str.endswith(). str.startswith(prefix[, start[, end]]) As it's name implies, str.startswith is used to test whether a given string starts with the given characters in prefix. >...
NaN ("Not a Number") is a special value defined by the IEEE Standard for Floating-Point Arithmetic, which is used when a non-numeric value is provided but a number is expected (1 * "two"), or when a calculation doesn't have a valid number result (Math.sqrt(-1)). Any equality or ...
try { JTextPane pane = new JTextPane(); StyledDocument doc = new DefaultStyledDocument(); doc.insertString(0, "Some text", null); pane.setDocument(doc); //Technically takes any subclass of Document } catch (BadLocationException ex) { //hand...
// Animal.php class Animal { public function eats($food) { echo "Yum, $food!"; } } // zoo.php require 'Animal.php'; $animal = new Animal; $animal->eats('slop'); // aquarium.php require 'Animal.php'; $animal = new Animal; $animal->eats('shrimp'); H...
// autoload.php spl_autoload_register(function ($class) { require_once "$class.php"; }); // Animal.php class Animal { public function eats($food) { echo "Yum, $food!"; } } // zoo.php require 'autoload.php'; $animal = new Animal; $animal->e...
6 Fetch request promises initially return Response objects. These will provide response header information, but they don't directly include the response body, which may not have even loaded yet. Methods on the Response object such as .json() can be used to wait for the response body to load, then p...
Getters and setters allow you to define custom behaviour for reading and writing a given property on your class. To the user, they appear the same as any typical property. However, internally a custom function you provide is used to determine the value when the property is accessed (the getter), and...
If it's not already done in php.ini, error reporting can be set dynamically and should be set to allow most errors to be shown: Syntax int error_reporting ([ int $level ] ) Examples // should always be used prior to 5.4 error_reporting(E_ALL); // -1 will show every possible error, even whe...
It is possible to create an anonymous struct: data := struct { Number int Text string } { 42, "Hello world!", } Full example: package main import ( "fmt" ) func main() { data := struct {Number int; Text string}{42, "Hello worl...
try/catch try..catch blocks can be used to control the flow of a program where Exceptions may be thrown. They can be caught and handled gracefully rather than letting PHP stop when one is encountered: try { // Do a bunch of things... throw new Exception('My test exception!'); } catch (E...
Usually, you have to use git add or git rm to add changes to the index before you can git commit them. Pass the -a or --all option to automatically add every change (to tracked files) to the index, including removals: git commit -a If you would like to also add a commit message you would do: g...
Right after you install Git, the first thing you should do is set your username and email address. From a shell, type: git config --global user.name "Mr. Bean" git config --global user.email [email protected] git config is the command to get or set options --global means that the ...
Creating jobs To create an job, just append a single & after the command: $ sleep 10 & [1] 20024 You can also make a running process a job by pressing Ctrl + z: $ sleep 10 ^Z [1]+ Stopped sleep 10 Background and foreground a process To bring the Process to the f...
The function rand() can be used to generate a pseudo-random integer value between 0 and RAND_MAX (0 and RAND_MAX included). srand(int) is used to seed the pseudo-random number generator. Each time rand() is seeded wih the same seed, it must produce the same sequence of values. It should only be see...
> redirect the standard output (aka STDOUT) of the current command into a file or another descriptor. These examples write the output of the ls command into the file file.txt ls >file.txt > file.txt ls The target file is created if it doesn't exists, otherwise this file is truncated. ...

Page 12 of 307