@supriyo_biswas

#include <stdio.h>

int main() {
    // two int variables and pointers pointing to them
    int x = 10, *p = &x;
    int y = 20, *q = &y;

    // create a pointer-to-pointer, pointing to p
    int **r = &p;

    // print the value of x through r.

Pointers: constant pointers

updated January 03, 2020 · C
#include <stdio.h>

int main() {
    // declare two variables.
    int x = 10, y = 20;

    // declare a constant pointer to the variable x
    int *const p = &x;

    // print the value of a through x.
    printf("The value of x is %d\n", *p);

Pointers: constant pointers

December 29, 2019 · C
#include <stdio.h>

int main() {
    // declare two const-qualified variables.
    const int x = 10, y = 20;

    // declare a pointer to the const-qualified variable x
    const int *p = &x;

    // print the value of a through x.
    printf("The value of x is %d\n", *p);

Pointers: Using the pointer constant syntax

updated December 19, 2019 · C
#include <stdio.h>

void print_array(int q[], int size) {
    // q is a pointer constant.

    int i;

    for (i = 0; i < size; i++) {
        printf("%d ", q[i]);
    }
}

Pointers: Using the pointer constant syntax

updated January 04, 2020 · C
#include <stdio.h>

void add_one(int q[]) {
    // because 'q' is just a special kind of pointer
    // called a constant pointer, this statement works
    // as you would expect.

    *q = *q + 1;
}

int main() {

Pointers: passing arrays to functions

updated December 19, 2019 · C
#include <stdio.h>

void add_one(int *b, int size) {
    int i;

    // add one to each element of b
    for (i = 0; i < size; i++) {
        b[i]++;
    }
}

Pointers: Simulating call by reference

updated December 17, 2019 · C
#include <stdio.h>

void add_one(int *q) {
    printf("initial value of *q from add_one() = %d\n", *q);
    *q = *q + 1;
    printf("final value of *q from add_one() = %d\n", *q);
}

int main() {
    int x = 10, *p = &x;
    printf("initial value of x from main() = %d\n", x);
#include <stdio.h>

void add_one(int v) {
    printf("initial value of v from add_one() = %d\n", v);
    v = v + 1;
    printf("final value of v from add_one() = %d\n", v);
}

int main() {
    int x = 10;
    printf("initial value of x from main() = %d\n", x);
#include <stdio.h>

int main() {
    // declare two integers.
    int a = 10, b = 20;

    // declare two pointers pointing to 'a' and 'b'.
    int *p = &a, *q = &b;

    // working with relational operators and pointers.
    if (p == q) {
#include <stdio.h>

int main() {
    // two integers.
    int a = 10, b = 20;

    // two pointers, pointing to 'a' and 'b'
    int *p = &a, *q = &b;

    // print the difference between the pointers
    printf("Difference between p and q is %d\n", p - q);
#include <stdio.h>

int main() {
    // an array.
    int a[] = {10, 20, 30, 40};

    // a pointer p, with the same value as a.
    int *p = a;

    // a loop variable.
    int i = 0;
#include <stdio.h>

int main() {
    // An array of four elements.
    // Remember that "a" is a "constant pointer".
    int a[] = {10, 20, 30, 40};

    // A loop variable.
    int i;

    // Print the array elements and their address
#include <stdio.h>

int main() {
    // An array of four elements.
    // Remember that "a" is a "constant pointer".
    int a[] = {10, 20, 30, 40};

    // A loop variable.
    int i;

    // Print the array elements and their address
#include <stdio.h>

int main() {
    int a = 10;

    // get the address of a and store it in p.
    int *p = &a;

    // add 10 to p and store it in q.
    int *q = p + 10;

Pointers: pointers and arrays.

December 11, 2019 · C
#include <stdio.h>

int main() {
    // declaring an array and a loop variable.
    int a[] = {10, 20, 30, 40}, i;

    // because 'a' behaves like an array and
    // stores an address, copy the address into
    // a pointer p.
    int *p = a;

Pointers: void pointers

December 06, 2019 · C
#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
    *(int*)p = 100;
#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.
    *p = 20;
#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;
    printf("p now has the value of %p\n", p);

A Tour Of Go - Advanced Types - Slice defaults

updated November 24, 2019 · Go
// 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

updated November 24, 2019 · Go
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)