S

@supriyo_biswas

Pointers: void pointers

C
6 years ago
#include <stdio.h> int main() { int a = 10; void *p = &a; // printing a through p printf("value of a is %d\n", *(int*)p); // setting a to 100 through p

Pointers: indirection operator and dereferencing

C
6 years ago
#include <stdio.h> int main() { int a = 10; int *p = &a; // print the value without using a pointer. printf("The current value of a is %d\n", a); // update the value and print it through the pointer.

Printing pointer addresses using the %p format specifier

C
6 years ago
#include <stdio.h> int main() { int a = 10, b = 20; int *p; p = &a; printf("p has the current value of %p\n", p); p = &b;

A Tour Of Go - Advanced Types - Slice defaults

Go
6 years ago
// when one of the low:high indices are omitted, // it defaults to 0:length. package main import "fmt" func main() { a := []int{2, 3, 5, 7, 11, 13} fmt.Println(a)

A Tour Of Go - Advanced Types - Slice literal

Go
6 years ago
package main import "fmt" func main() { // this is equivalent to: // p := []int{2, 3, 5, 7, 11, 13} // primes := p[0:6] primes := []int{2, 3, 5, 7, 11, 13} fmt.Println(primes)

A Tour Of Go - Advanced Types - Slices

Go
6 years ago
// slices are a dynamically sized, flexible // view of the array. []T represents a slice, // whereas [n]T represents an array. package main import "fmt" func main() { primes := [6]int{2, 3, 5, 7, 11, 13}

A Tour Of Go - Advanced Types - Arrays

Go
6 years ago
package main import "fmt" func main() { // declaring a fixed size array var a [2]string a[0] = "Hello" a[1] = "World"

A Tour Of Go - Advanced Types - Pointers to Structs

Go
6 years ago
// A struct is a collection of 'fields' package main import "fmt" type Vertex struct { X int Y int }

A Tour Of Go - Advanced Types - Structs

Go
6 years ago
// A struct is a collection of 'fields' package main import "fmt" type Vertex struct { X int Y int }

A Tour Of Go - Advanced Types - Pointers

Go
6 years ago
// Pointers hold the memory address of a type. // *T represents a pointer to T. zero value is nil. package main import "fmt" func main() { var i int = 10

A Tour Of Go - Flow Control - Stacking defers

Go
6 years ago
package main import "fmt" func main() { // When multiple calls were deferred, the // calls are executed in LIFO order. defer fmt.Println("liftoff!")

A Tour Of Go - Flow Control - Defer

Go
6 years ago
package main import "fmt" func main() { // A defer statement defers the execution of a // function until the function where said "deferred // function" resides also returns. The deferred // call arguments are evaluated immediately, though.

A Tour Of Go - Flow Control - Switch with no condition

Go
6 years ago
package main import ( "fmt" "time" ) func main() { t := time.Now()

A Tour Of Go - Flow Control - Switch statement with non-constants

Go
6 years ago
package main import ( "fmt" "math/rand" ) func main() { z := 1 switch z {

A Tour Of Go - Flow Control - Switch statement

Go
6 years ago
package main import ( "fmt" "runtime" ) func main() { fmt.Print("Go runs on ") // this is a switch statement.

Implementing Newton-Raphson method for square root

Go
6 years ago
// See: // https://en.wikipedia.org/wiki/Newton%27s_method // In general, repeat: // $$ x_{n + 1} = x_{n} - f(x_{n})/f'(x_{n}) $$ // starting from $$ x_{0} $$, an initial guess. package main import "fmt"

A tour of Go - Flow Control - If/Else with a short statement

Go
6 years ago
package main import ( "fmt" "math" ) func cappedPow(x, n, lim float64) float64 { // executing a short statement before the // actual condition occurs. the statement

A tour of Go - Flow Control - If with a short statement

Go
6 years ago
package main import ( "fmt" "math" ) func cappedPow(x, n, lim float64) float64 { // executing a short statement before the // actual condition occurs.

A tour of Go - Flow Control - If statements

Go
6 years ago
package main import ( "fmt" "math" ) func sqrt(x float64) string { // just like any other programming language's // if statement

A tour of Go - Flow Control - For is Go's while

Go
6 years ago
package main import "fmt" func main() { i := 10 // omitting the initialization and update // statements, but keeping the condition // check.