C-Type-Declarations-without-const

Declaration

Description

char x;

x is a variable of type char with storage of 1 byte

int x;

x is a variable of type int with storage of 4 bytes

float x;

x is a variable of type float with storage of 4 bytes

double x;

x is a variable of type double with storage of 8 bytes

struct ABC x;

x is a variable of type struct ABC

union ABC x;

x is a variable of type union ABC

char x[10];

x is an array of 10 blocks where each block is of type char and each block is of size 1 byte

int x[10];

x is an array of 10 blocks where each block is of type int and each block is of size 4 bytes

float x[10];

x is an array of 10 floats where each block is of type float and each block is of size 4 bytes

double x[10];

x is an array of 10 doubles where each block is of type double and each block is of size 8 bytes

struct ABC x[10];

x is an array of 10 structure instances of type struct ABC

union ABC x[10];

x is an array of 10 union instances of type union ABC

char x[3][4];

x is a two dimensional array of 3 rows, 4 columns, i.e., x is made of 3 single dimension arrays, with each single dimension array having 4 characters

int x[3][4];

x is a two dimensional array of 3 rows, 4 columns, i.e., x is made of 3 single dimension arrays, with each single dimension array having 4 integers

float x[3][4];

x is a two dimensional array of 3 rows, 4 columns, i.e., x is made of 3 single dimension arrays, with each single dimension array having 4 floats

doubles x[3][4];

x is a two dimensional array of 3 rows, 4 columns, i.e., x is made of 3 single dimension arrays, with each single dimension array having 4 doubles

struct ABC x[3][4];

x is a two dimensional array of 3 rows, 4 columns, i.e., x is made of 3 single dimension arrays, with each single dimension array having 4 structure instances

union ABC x[3][4];

x is a two dimensional array of 3 rows, 4 columns, i.e., x is made of 3 single dimension arrays, with each single dimension array having 4 union instances

char x[3][4][5];

x is a three dimensional array of characters, i.e., x is made of 3 two dimensional arrays of 4 rows, 5 columns, where each of 4 rows is a single dimension array having 5 characters

int x[3][4][5];

x is a three dimensional array of integers, i.e., x is made of 3 two dimensional arrays of 4 rows, 5 columns, where each of 4 rows is a single dimension array having 5 integers

float x[3][4][5];

x is a three dimensional array of floats, i.e., x is made of 3 two dimensional arrays of 4 rows, 5 columns, where each of 4 rows is a single dimension array having 5 floats

double x[3][4][5];

x is a three dimensional array of doubles, i.e., x is made of 3 two dimensional arrays of 4 rows, 5 columns, where each of 4 rows is a single dimension array having 5 doubles

struct ABC x[3][4][5];

x is a three dimensional array of structure instances, i.e., x is made of 3 two dimensional arrays of 4 rows, 5 columns, where each of 4 rows is a single dimension array having 5 structure instances

union ABC x[3][4][5];

x is a three dimensional array of union instances, i.e., x is made of 3 two dimensional arrays of 4 rows, 5 columns, where each of 4 rows is a single dimension array having 5 union instances

char *x;

x is a pointer which can hold the address of a single character or array of characters (Single dimension array of characters)

int *x;

x is a pointer which can hold the address of a single integer or array of integers (Single dimension array of integers)

float *x;

x is a pointer which can hold the address of a single float or array of floats (Single dimension array of floats)

double *x;

x is a pointer which can hold the address of a single double or array of doubles (Single dimension arrray of doubles)

struct ABC *x;

x is a pointer which can hold the address of a single structure instance or array of structure instances of type struct ABC (Single dimension array of structure instances)

union ABC *x;

x is a pointer which can hold the address of a single union instance or array of union instances of type union ABC (Single dimension array of union instances)

char **x;

x is a pointer which can hold the address of more than one memory blocks, where each of the memory blocks can hold the address of a single character variable or array of characters

int **x;

x is a pointer which can hold the address of more than one memory blocks, where each of the memory blocks can hold the address of a single instance variable or array of integers

float **x;

x is a pointer which can hold the address of more than one memory blocks, where each of the memory blocks can hold the address of a single float variable or array of floats

double **x;

x is a pointer which can hold the address of more than one memory blocks, where each of the memory blocks can hold the address of a single double variable or array of doubles

struct ABC **x;

x is a pointer which can hold the address of more than one memory blocks, where each of the memory blocks can hold the address of a single structure instance or array of structure instances

union ABC **x;

x is a pointer which can hold the address of more than one memory blocks, where each of the memory blocks can hold the address of a single union instance or array of union instances

char *x[10];

x is an array of 10 character pointers, where each pointer can hold the address of a single character or array of characters (Single dimension array of characters)

int *x[10];

x is an array of 10 integer pointers, where each pointer can hold the address of a single integer or array of integers (Single dimension array of integers)

float *x[10];

x is an array of 10 float pointers, where each pointer can hold the address of a single float or array of floats (Single dimension array of floats)

double *x[10];

x is an array of 10 double pointers, where each pointer can hold the address of a single double or array of doubles (Single dimension array of doubles)

struct ABC *x[10];

x is an array of 10 structure pointers, where each pointer can hold the address of a single structure instance or array of structure instances (Single dimension array of structure instances)

union ABC *x[10];

x is an array of 10 union pointers, where each pointer can hold the address of a single union instance or array of union instances (Single dimension array of union instances)

char (*x)[10];

x is a pointer to an array, which can hold the address of a two dimensional array of characters

int (*x)[10];

x is a pointer to an array, which can hold the address of a two dimensional array of integers

float (*x)[10];

x is a pointer to an array, which can hold the address of a two dimensional array of floats

double (*x)[10];

x is a pointer to an array, which can hold the address of a two dimensional array of doubles

struct ABC (*x)[10];

x is a pointer to an array, which can hold the address of a two dimensional array of structure instances

union ABC (*x)[10];

x is a pointer to an array, which can hold the address of a two dimensional array of union instances

char (*x)[3][4];

x is a pointer to an array, which can hold the address of a three dimensional array of characters

int (*x)[3][4];

x is a pointer to an array, which can hold the address of a three dimensional array of integers

float (*x)[3][4];

x is a pointer to an array, which can hold the address of a three dimensional array of floats

double (*x)[3][4];

x is a pointer to an array, which can hold the address of a three dimensional array of doubles

struct ABC (*x)[3][4];

x is a pointer to an array, which can hold the address of a three dimensional array of structure instances

union ABC (*x)[3][4];

x is a pointer to an array, which can hold the address of a three dimensional array of union instances

C-Type-Declarations-with-const

const char

Description

int main()
{
	const char x = 10;
	x =100; // --> This is not valid
	return 0;
}

x is a character constant which can not be changed once intialised during declaration

const int

Description

int main()
{
	const int x = 10;
	x =100; // --> This is not valid
	return 0;
}

x is a integer constant which can not be changed once intialised during declaration

const float

Description

int main()
{
	const float x = 10.23;
	x =100.3243; // --> This is not valid
	return 0;
}

x is a float constant which can not be changed once intialised during declaration

const double

Description

int main()
{
	const double x = 10.23432;
	x = 5.423432; // --> This is not valid
	return 0;
}

x is a double constant which can not be changed once intialised during declaration

const struct

Description

struct ABC
{
    int a;
    int b;
};

const struct ABC x = { .a = 1, .b = 2 };

int main()
{
    x.a = 100; // This is not valid
    x.b = 100; // This is not valid
    return 0;
}

x is a structure instance constant which can not be changed once intialised during declaration

const union

Description

union ABC
{
    int a;
    int b;
};

const union ABC x = { .a = 1, .b = 2 };

int main()
{
    x.a = 100; // This is not valid
    x.b = 100; // This is not valid
    return 0;
}

x is a union instance constant which can not be changed once intialised during declaration

const char single dimension array

Description

int main()
{
    const char x[10] = "Bengaluru";
    x[0] = 'K'; //This is not valid
    return 0;
}

x is a single dimensional character array which can nan not be changed once initialised

const int single dimension array

Description

int main()
{
    const int x[5] = {1,2,3,4,5};
    x[0] = 100;// This is not valid
    return 0;
}

x is a single dimensional integer array which can nan not be changed once initialised

const float single dimension array

Description

int main()
{
    const float x[5] = {1.1,2.2,3.3,4.44,5.433};
    x[0] = 100.13123;// This is not valid
    return 0;
}

x is a single dimensional float array which can nan not be changed once initialised

const double single dimension array

Description

int main()
{
    const double x[5] = {1.1,2.2,3.3,4.44,5.433};
    x[0] = 100.13123;// This is not valid
    return 0;
}

x is a single dimensional double array which can nan not be changed once initialised

const struct single dimension array

Description

#include <stdio.h>
#include <string.h>

struct ABC
{
    int a;
    int b;
    char str[10];
};

const struct ABC x[5] = {
        { .a = 10, .b = 20, .str = "c-pro" },
        { .a = 30, .b = 40, .str = "gramming" },
        { .a = 50, .b = 60, .str = "learning" },
        { .a = 70, .b = 80, .str = "is" },
        { .a = 90, .b = 100, .str = "fun"},
    };

int main()
{
    x[0].a = 100; // This is not valid
    x[0].b = 200; // This is not valid
    x[0].str[2] = 'K'; // This is not valid

    // This is not valid and fails at runtime
    memcpy((void *)x[0].str, "Beng", 10);

    return 0;
}

x is a single dimensional struct array which can nan not be changed once initialised

const union single dimension array

Description

#include <stdio.h>
#include <string.h>

union ABC
{
    int a;
    int b;
    char str[10];
};

const union ABC x[5] = {
        { .a = 10, .b = 20, .str = "c-pro" },
        { .a = 30, .b = 40, .str = "gramming" },
        { .a = 50, .b = 60, .str = "learning" },
        { .a = 70, .b = 80, .str = "is" },
        { .a = 90, .b = 100, .str = "fun"},
    };

int main()
{
    x[0].a = 100; // This is not valid
    x[0].b = 200; // This is not valid
    x[0].str[2] = 'K'; // This is not valid

    // This is not valid and fails at runtime
    memcpy((void *)x[0].str, "Beng", 10);

    return 0;
}

x is a single dimensional union array which can nan not be changed once initialised

const char two dimension array

Description

#include <stdio.h>
#include <string.h>

const char x[4][10] = {
    {"learning"},
    {"c progra"},
    {"mming is"},
    {"fun"},
};

const char y[4][10] = {
    {'l', 'e', 'a', 'r', 'n','i', 'n', 'g', '\0' },
    {'c',' ', 'p', 'r', 'o', 'g', 'r', 'a', '\0'},
    {'m', 'm', 'i', 'n', 'g', 'i', 's', '\0'},
    {'f','u','n', '\0'},
};

int main()
{
    x[0][0] = 'k'; // This is not valid
    x[1][2] = 'h'; // This is not valid

    y[0][0] = 'k'; // This is not valid
    y[1][2] = 'h'; // This is not valid

    // This is not valid, and fails at runtime
    memcpy(x[0], y[0], 10);

    return 0;
}

x is a two dimensional character array which can nan not be changed once initialised

const int two dimension array

Description

#include <stdio.h>
#include <string.h>

const int x[4][3] = {
    {1,2,3},
    {4,5,6},
    {7,8,9},
    {10,11,12},
};

const int y[4][3] = {
    {100,200,300},
    {400,500,600},
    {700,800,900},
    {1000,2000,3000},
};

int main()
{
    x[0][0] = 100; // This is not valid
    x[1][2] = 200; // This is not valid

    y[0][0] = 300; // This is not valid
    y[1][2] = 400; // This is not valid

    // This is not valid, and fails at runtime
    memcpy((void *)x[0], (void *)y[0], 10);

    return 0;
}

x is a two dimensional integer array which can nan not be changed once initialised

const float two dimension array

Description

#include <stdio.h>
#include <string.h>

const float x[4][3] = {
    {1,2,3},
    {4,5,6},
    {7,8,9},
    {10,11,12},
};

const float y[4][3] = {
    {100,200,300},
    {400,500,600},
    {700,800,900},
    {1000,2000,3000},
};

int main()
{
    x[0][0] = 100; // This is not valid
    x[1][2] = 200; // This is not valid

    y[0][0] = 300; // This is not valid
    y[1][2] = 400; // This is not valid

    // This is not valid, and fails at runtime
    memcpy((void *)x[0], (void *)y[0], 10);

    return 0;
}

x is a two dimensional float array which can nan not be changed once initialised

const double two dimension array

Description

#include <stdio.h>
#include <string.h>

const double x[4][3] = {
    {1,2,3},
    {4,5,6},
    {7,8,9},
    {10,11,12},
};

const double y[4][3] = {
    {100,200,300},
    {400,500,600},
    {700,800,900},
    {1000,2000,3000},
};

int main()
{
    x[0][0] = 100; // This is not valid
    x[1][2] = 200; // This is not valid

    y[0][0] = 300; // This is not valid
    y[1][2] = 400; // This is not valid

    // This is not valid, and fails at runtime
    memcpy((void *)x[0], (void *)y[0], 10);

    return 0;
}

x is a two dimensional double array which can nan not be changed once initialised

const struct two dimension array

Description

#include <stdio.h>
#include <string.h>

struct ABC
{
    int a;
    int b;
    char str[10];
};

const struct ABC x[3][5] =
{
        { //Start of x[0]
                { .a = 10, .b = 20, .str = "c-pro" },
                { .a = 30, .b = 40, .str = "gramming" },
                { .a = 50, .b = 60, .str = "learning" },
                { .a = 70, .b = 80, .str = "is" },
                { .a = 90, .b = 100, .str = "fun"},
        },
        { //Start of x[1]
                { .a = 120, .b = 130, .str = "c-pro" },
                { .a = 140, .b = 150, .str = "gramming" },
                { .a = 160, .b = 170, .str = "learning" },
                { .a = 180, .b = 190, .str = "is" },
                { .a = 200, .b = 210, .str = "fun"},
        },
        { //Start of x[2]
                { .a = 300, .b = 350, .str = "c-pro" },
                { .a = 400, .b = 450, .str = "gramming" },
                { .a = 500, .b = 550, .str = "learning" },
                { .a = 600, .b = 650, .str = "is" },
                { .a = 700, .b = 750, .str = "fun"},
        }
};

int main()
{

    x[0][0].a = 'k'; //This is not valid

    return 0;
}

x is a two dimensional struct array which can nan not be changed once initialised

const union two dimension array

Description

#include <stdio.h>
#include <string.h>

union ABC
{
    int a;
    int b;
    char str[10];
};

const union ABC x[3][5] =
{
        { //Start of x[0]
                { .a = 10, .b = 20, .str = "c-pro" },
                { .a = 30, .b = 40, .str = "gramming" },
                { .a = 50, .b = 60, .str = "learning" },
                { .a = 70, .b = 80, .str = "is" },
                { .a = 90, .b = 100, .str = "fun"},
        },
        { //Start of x[1]
                { .a = 120, .b = 130, .str = "c-pro" },
                { .a = 140, .b = 150, .str = "gramming" },
                { .a = 160, .b = 170, .str = "learning" },
                { .a = 180, .b = 190, .str = "is" },
                { .a = 200, .b = 210, .str = "fun"},
        },
        { //Start of x[2]
                { .a = 300, .b = 350, .str = "c-pro" },
                { .a = 400, .b = 450, .str = "gramming" },
                { .a = 500, .b = 550, .str = "learning" },
                { .a = 600, .b = 650, .str = "is" },
                { .a = 700, .b = 750, .str = "fun"},
        }
};

int main()
{

    x[0][0].a = 'k'; //This is not valid

    return 0;
}

x is a two dimensional union array which can nan not be changed once initialised

const char three dimension array

Description

#include <stdio.h>
#include <string.h>

const char x[3][4][10] =
{
        {//start of x[0]
                {"learning"},
                {"c progra"},
                {"mming is"},
                {"fun"},
        },
        {//start of x[1]
                {"because"},
                {"it is"},
                {"very"},
                {"cool"},
        },
        {//start of x[1]
                {"and"},
                {"challen"},
                {"ging and"},
                {"interest"},
        },
};

int main()
{
    x[1][2][3] = 'j';

    return 0;
}

x is a three dimensional character array which can nan not be changed once initialised

const int three dimension array

Description

#include <stdio.h>
#include <string.h>

const int x[2][4][3] =
{
        {//start of x[0]
                {1,2,3},
                {4,5,6},
                {7,8,9},
                {10,11,12},
        },
        {//start of x[1]
                {1,2,3},
                {4,5,6},
                {7,8,9},
                {10,11,12},
        },
};

int main()
{
    x[0][1][2] = 100; //This is not valid

    return 0;
}

x is a three dimensional integer array which can nan not be changed once initialised

const float three dimension array

Description

#include <stdio.h>
#include <string.h>

const float x[2][4][3] =
{
        {//start of x[0]
                {1,2,3},
                {4,5,6},
                {7,8,9},
                {10,11,12},
        },
        {//start of x[1]
                {1,2,3},
                {4,5,6},
                {7,8,9},
                {10,11,12},
        },
};

int main()
{
    x[0][1][2] = 100; //This is not valid

    return 0;
}

x is a three dimensional float array which can nan not be changed once initialised

const double three dimension array

Description

#include <stdio.h>
#include <string.h>

const double x[2][4][3] =
{
        {//start of x[0]
                {1,2,3},
                {4,5,6},
                {7,8,9},
                {10,11,12},
        },
        {//start of x[1]
                {1,2,3},
                {4,5,6},
                {7,8,9},
                {10,11,12},
        },
};

int main()
{
    x[0][1][2] = 100; //This is not valid

    return 0;
}

x is a three dimensional double array which can nan not be changed once initialised

const struct three dimension array

Description

#include <stdio.h>
#include <string.h>

struct ABC
{
    int a;
    int b;
    char str[10];
};

const struct ABC x[2][3][5] =
{
        {//Start x[0]
                { //Start of x[0][0]
                        { .a = 10, .b = 20, .str = "c-pro" },
                        { .a = 30, .b = 40, .str = "gramming" },
                        { .a = 50, .b = 60, .str = "learning" },
                        { .a = 70, .b = 80, .str = "is" },
                        { .a = 90, .b = 100, .str = "fun"},
                },
                { //Start of x[0][1]
                        { .a = 120, .b = 130, .str = "c-pro" },
                        { .a = 140, .b = 150, .str = "gramming" },
                        { .a = 160, .b = 170, .str = "learning" },
                        { .a = 180, .b = 190, .str = "is" },
                        { .a = 200, .b = 210, .str = "fun"},
                },
                { //Start of x[0][2]
                        { .a = 300, .b = 350, .str = "c-pro" },
                        { .a = 400, .b = 450, .str = "gramming" },
                        { .a = 500, .b = 550, .str = "learning" },
                        { .a = 600, .b = 650, .str = "is" },
                        { .a = 700, .b = 750, .str = "fun"},
                }
        },
        {//Start of x[1]
                { //Start of x[1][0]
                        { .a = 10, .b = 20, .str = "c-pro" },
                        { .a = 30, .b = 40, .str = "gramming" },
                        { .a = 50, .b = 60, .str = "learning" },
                        { .a = 70, .b = 80, .str = "is" },
                        { .a = 90, .b = 100, .str = "fun"},
                },
                { //Start of x[1][1]
                        { .a = 120, .b = 130, .str = "c-pro" },
                        { .a = 140, .b = 150, .str = "gramming" },
                        { .a = 160, .b = 170, .str = "learning" },
                        { .a = 180, .b = 190, .str = "is" },
                        { .a = 200, .b = 210, .str = "fun"},
                },
                { //Start of x[1][2]
                        { .a = 300, .b = 350, .str = "c-pro" },
                        { .a = 400, .b = 450, .str = "gramming" },
                        { .a = 500, .b = 550, .str = "learning" },
                        { .a = 600, .b = 650, .str = "is" },
                        { .a = 700, .b = 750, .str = "fun"},
                }
        },
};

int main()
{
    x[1][0][2].a = 200; // This is not valid

    return 0;
}

x is a three dimensional struct array which can nan not be changed once initialised

const union three dimension array

Description

#include <stdio.h>
#include <string.h>

union ABC
{
    int a;
    int b;
    char str[10];
};

const union ABC x[2][3][5] =
{
        {//Start x[0]
                { //Start of x[0][0]
                        { .a = 10, .b = 20, .str = "c-pro" },
                        { .a = 30, .b = 40, .str = "gramming" },
                        { .a = 50, .b = 60, .str = "learning" },
                        { .a = 70, .b = 80, .str = "is" },
                        { .a = 90, .b = 100, .str = "fun"},
                },
                { //Start of x[0][1]
                        { .a = 120, .b = 130, .str = "c-pro" },
                        { .a = 140, .b = 150, .str = "gramming" },
                        { .a = 160, .b = 170, .str = "learning" },
                        { .a = 180, .b = 190, .str = "is" },
                        { .a = 200, .b = 210, .str = "fun"},
                },
                { //Start of x[0][2]
                        { .a = 300, .b = 350, .str = "c-pro" },
                        { .a = 400, .b = 450, .str = "gramming" },
                        { .a = 500, .b = 550, .str = "learning" },
                        { .a = 600, .b = 650, .str = "is" },
                        { .a = 700, .b = 750, .str = "fun"},
                }
        },
        {//Start of x[1]
                { //Start of x[1][0]
                        { .a = 10, .b = 20, .str = "c-pro" },
                        { .a = 30, .b = 40, .str = "gramming" },
                        { .a = 50, .b = 60, .str = "learning" },
                        { .a = 70, .b = 80, .str = "is" },
                        { .a = 90, .b = 100, .str = "fun"},
                },
                { //Start of x[1][1]
                        { .a = 120, .b = 130, .str = "c-pro" },
                        { .a = 140, .b = 150, .str = "gramming" },
                        { .a = 160, .b = 170, .str = "learning" },
                        { .a = 180, .b = 190, .str = "is" },
                        { .a = 200, .b = 210, .str = "fun"},
                },
                { //Start of x[1][2]
                        { .a = 300, .b = 350, .str = "c-pro" },
                        { .a = 400, .b = 450, .str = "gramming" },
                        { .a = 500, .b = 550, .str = "learning" },
                        { .a = 600, .b = 650, .str = "is" },
                        { .a = 700, .b = 750, .str = "fun"},
                }
        },
};

int main()
{
    x[1][0][2].a = 200; // This is not valid

    return 0;
}

x is a three dimensional union array which can nan not be changed once initialised

const char single pointer

Description

#include <stdio.h>
#include <string.h>

int fun_1()
{
    char x = 'A';
    char y = 'B';
    const char *ptr = &x;

    *ptr = 'M'; // This is not valid
    ptr = &y;   // This is valid
    *ptr = 'N'; // This is not valid
    return 0;
}

int fun_2()
{
    char x = 'A';
    char y = 'B';
    char *const ptr = &x;

    *ptr = 'M'; // This is valid
    ptr = &y;   // This is not valid

    return 0;
}

int fun_3()
{
    char x = 'A';
    char y = 'B';
    const char *const ptr = &x;

    *ptr = 'M'; // This is not valid
    ptr = &y;   // This is not valid

    return 0;
}
const char *ptr; ptr can be changed. *ptr can not be changed
char *const ptr; ptr can not be changed. *ptr can be changed
const char *const ptr; ptr can not be changed. *ptr can not be changed

const int single pointer

Description

#include <stdio.h>
#include <string.h>

int fun_1()
{
    int x = 100;
    int y = 200;
    const int *ptr = &x;

    *ptr = 10; // This is not valid
    ptr = &y;   // This is valid
    *ptr = 20; // This is not valid
    return 0;
}

int fun_2()
{
    int x = 100;
    int y = 200;
    int *const ptr = &x;

    *ptr = 10; // This is valid
    ptr = &y;   // This is not valid

    return 0;
}

int fun_3()
{
    int x = 100;
    int y = 200;
    const int *const ptr = &x;

    *ptr = 10; // This is not valid
    ptr = &y;   // This is not valid

    return 0;
}
const int *ptr; ptr can be changed. *ptr can not be changed
int *const ptr; ptr can not be changed. *ptr can be changed
const int *const ptr; ptr can not be changed. *ptr can not be changed

const float single pointer

Description

#include <stdio.h>
#include <string.h>

float fun_1()
{
    float x = 100;
    float y = 200;
    const float *ptr = &x;

    *ptr = 10; // This is not valid
    ptr = &y;   // This is valid
    *ptr = 20; // This is not valid
    return 0;
}

float fun_2()
{
    float x = 100;
    float y = 200;
    float *const ptr = &x;

    *ptr = 10; // This is valid
    ptr = &y;   // This is not valid

    return 0;
}

float fun_3()
{
    float x = 100;
    float y = 200;
    const float *const ptr = &x;

    *ptr = 10; // This is not valid
    ptr = &y;   // This is not valid

    return 0;
}
const float *ptr; ptr can be changed. *ptr can not be changed
float *const ptr; ptr can not be changed. *ptr can be changed
const float *const ptr; ptr can not be changed. *ptr can not be changed

const double single pointer

Description

#include <stdio.h>
#include <string.h>

double fun_1()
{
    double x = 100;
    double y = 200;
    const double *ptr = &x;

    *ptr = 10; // This is not valid
    ptr = &y;   // This is valid
    *ptr = 20; // This is not valid
    return 0;
}

double fun_2()
{
    double x = 100;
    double y = 200;
    double *const ptr = &x;

    *ptr = 10; // This is valid
    ptr = &y;   // This is not valid

    return 0;
}

double fun_3()
{
    double x = 100;
    double y = 200;
    const double *const ptr = &x;

    *ptr = 10; // This is not valid
    ptr = &y;   // This is not valid

    return 0;
}
const double *ptr; ptr can be changed. *ptr can not be changed
double *const ptr; ptr can not be changed. *ptr can be changed
const double *const ptr; ptr can not be changed. *ptr can not be changed

const struct single pointer

Description

#include <stdio.h>
#include <string.h>

struct ABC
{
    int a;
    int b;
};

int fun_1()
{
    struct ABC x, y;
    const struct ABC *ptr = &x;

    ptr->a = 100; // This is not valid
    ptr = &y;   // This is valid
    ptr->a = 200; // This is not valid
    return 0;
}

int fun_2()
{
    struct ABC x, y;
    struct ABC *const ptr = &x;

    ptr->a = 100; // This is valid
    ptr = &y;   // This is not valid

    return 0;
}

int fun_3()
{
    struct ABC x, y;
    const struct ABC *const ptr = &x;

    *ptr = 10; // This is not valid
    ptr = &y;   // This is not valid

    return 0;
}
const struct ABC *ptr; ptr can be changed. *ptr can not be changed
struct ABC *const ptr; ptr can not be changed. *ptr can be changed
const struct ABC *const ptr; ptr can not be changed. *ptr can not be changed

const union single pointer

Description

#include <stdio.h>
#include <string.h>

union ABC
{
    int a;
    int b;
};

int fun_1()
{
    union ABC x, y;
    const union ABC *ptr = &x;

    ptr->a = 100; // This is not valid
    ptr = &y;   // This is valid
    ptr->a = 200; // This is not valid
    return 0;
}

int fun_2()
{
    union ABC x, y;
    union ABC *const ptr = &x;

    ptr->a = 100; // This is valid
    ptr = &y;   // This is not valid

    return 0;
}

int fun_3()
{
    union ABC x, y;
    const union ABC *const ptr = &x;

    *ptr = 10; // This is not valid
    ptr = &y;   // This is not valid

    return 0;
}
const union ABC *ptr; ptr can be changed. *ptr can not be changed
union ABC *const ptr; ptr can not be changed. *ptr can be changed
const union ABC *const ptr; ptr can not be changed. *ptr can not be changed

const char double pointer

Description

#include <stdio.h>
#include <string.h>

void fun_1()
{
    char a = 'A'; char b = 'B';
    const char *ptr = &a;
    const char **qtr;

    qtr = &ptr; // This is valid
    *qtr = &b; // This is valid
    **qtr = 'C'; // This is not valid
}

void fun_2()
{
    char a = 'A'; char b = 'B';
    const char *ptr = &a;
    const char *const *qtr;

    qtr = &ptr; // This is valid
    *qtr = &b; // This is not valid
    **qtr = 'C'; // This is not valid
}

void fun_3()
{
    char a = 'A'; char b = 'B';
    const char *ptr = &a;
    const char *const *const qtr;

    qtr = &ptr; // This is not valid
    *qtr = &b; // This is not valid
    **qtr = 'C'; // This is not valid
}

void fun_4()
{
    char a = 'A'; char b = 'B';
    char *ptr = &a;
    char **const qtr = &ptr; // This is valid

    qtr = &ptr;// This is not valid
    *qtr = &b; // This is valid
    **qtr = 'C'; // This is valid
}

void fun_5()
{
    char a = 'A'; char b = 'B';
    char *ptr = &a;
    char *const *qtr = &ptr; // This is valid

    qtr = &ptr;// This is valid
    *qtr = &b; // This is not valid
    **qtr = 'C'; // This is valid
}
const char **qtr; qtr, *qtr can be changed. **qtr can not be changed
const char *const *qtr; qtr can be changed. *qtr, **qtr can not be changed
const char *const *const qtr; qtr, *qtr, **qtr can not be changed
char **const qtr; *qtr, **qtr can be changed. qtr can not be changed
char *const *qtr; qtr, **qtr can be changed. *qtr can not be changed

const int double pointer

Description

#include <stdio.h>
#include <string.h>

void fun_1()
{
    int a = 'A'; int b = 'B';
    const int *ptr = &a;
    const int **qtr;

    qtr = &ptr; // This is valid
    *qtr = &b; // This is valid
    **qtr = 'C'; // This is not valid
}

void fun_2()
{
    int a = 'A'; int b = 'B';
    const int *ptr = &a;
    const int *const *qtr;

    qtr = &ptr; // This is valid
    *qtr = &b; // This is not valid
    **qtr = 'C'; // This is not valid
}

void fun_3()
{
    int a = 'A'; int b = 'B';
    const int *ptr = &a;
    const int *const *const qtr;

    qtr = &ptr; // This is not valid
    *qtr = &b; // This is not valid
    **qtr = 'C'; // This is not valid
}

void fun_4()
{
    int a = 'A'; int b = 'B';
    int *ptr = &a;
    int **const qtr = &ptr; // This is valid

    qtr = &ptr;// This is not valid
    *qtr = &b; // This is valid
    **qtr = 'C'; // This is valid
}

void fun_5()
{
    int a = 'A'; int b = 'B';
    int *ptr = &a;
    int *const *qtr = &ptr; // This is valid

    qtr = &ptr;// This is valid
    *qtr = &b; // This is not valid
    **qtr = 'C'; // This is valid
}
const int **qtr; qtr, *qtr can be changed. **qtr can not be changed
const int *const *qtr; qtr can be changed. *qtr, **qtr can not be changed
const int *const *const qtr; qtr, *qtr, **qtr can not be changed
int **const qtr; *qtr, **qtr can be changed. qtr can not be changed
int *const *qtr; qtr, **qtr can be changed. *qtr can not be changed

const float double pointer

Description

#include <stdio.h>
#include <string.h>

void fun_1()
{
    float a = 'A'; float b = 'B';
    const float *ptr = &a;
    const float **qtr;

    qtr = &ptr; // This is valid
    *qtr = &b; // This is valid
    **qtr = 'C'; // This is not valid
}

void fun_2()
{
    float a = 'A'; float b = 'B';
    const float *ptr = &a;
    const float *const *qtr;

    qtr = &ptr; // This is valid
    *qtr = &b; // This is not valid
    **qtr = 'C'; // This is not valid
}

void fun_3()
{
    float a = 'A'; float b = 'B';
    const float *ptr = &a;
    const float *const *const qtr;

    qtr = &ptr; // This is not valid
    *qtr = &b; // This is not valid
    **qtr = 'C'; // This is not valid
}

void fun_4()
{
    float a = 'A'; float b = 'B';
    float *ptr = &a;
    float **const qtr = &ptr; // This is valid

    qtr = &ptr;// This is not valid
    *qtr = &b; // This is valid
    **qtr = 'C'; // This is valid
}

void fun_5()
{
    float a = 'A'; float b = 'B';
    float *ptr = &a;
    float *const *qtr = &ptr; // This is valid

    qtr = &ptr;// This is valid
    *qtr = &b; // This is not valid
    **qtr = 'C'; // This is valid
}
const float **qtr; qtr, *qtr can be changed. **qtr can not be changed
const float *const *qtr; qtr can be changed. *qtr, **qtr can not be changed
const float *const *const qtr; qtr, *qtr, **qtr can not be changed
float **const qtr; *qtr, **qtr can be changed. qtr can not be changed
float *const *qtr; qtr, **qtr can be changed. *qtr can not be changed

const double double pointer

Description

#include <stdio.h>
#include <string.h>

void fun_1()
{
    double a = 'A'; double b = 'B';
    const double *ptr = &a;
    const double **qtr;

    qtr = &ptr; // This is valid
    *qtr = &b; // This is valid
    **qtr = 'C'; // This is not valid
}

void fun_2()
{
    double a = 'A'; double b = 'B';
    const double *ptr = &a;
    const double *const *qtr;

    qtr = &ptr; // This is valid
    *qtr = &b; // This is not valid
    **qtr = 'C'; // This is not valid
}

void fun_3()
{
    double a = 'A'; double b = 'B';
    const double *ptr = &a;
    const double *const *const qtr;

    qtr = &ptr; // This is not valid
    *qtr = &b; // This is not valid
    **qtr = 'C'; // This is not valid
}

void fun_4()
{
    double a = 'A'; double b = 'B';
    double *ptr = &a;
    double **const qtr = &ptr; // This is valid

    qtr = &ptr;// This is not valid
    *qtr = &b; // This is valid
    **qtr = 'C'; // This is valid
}

void fun_5()
{
    double a = 'A'; double b = 'B';
    double *ptr = &a;
    double *const *qtr = &ptr; // This is valid

    qtr = &ptr;// This is valid
    *qtr = &b; // This is not valid
    **qtr = 'C'; // This is valid
}
const double **qtr; qtr, *qtr can be changed. **qtr can not be changed
const double *const *qtr; qtr can be changed. *qtr, **qtr can not be changed
const double *const *const qtr; qtr, *qtr, **qtr can not be changed
double **const qtr; *qtr, **qtr can be changed. qtr can not be changed
double *const *qtr; qtr, **qtr can be changed. *qtr can not be changed

const struct double pointer

Description

#include <stdio.h>
#include <string.h>

struct ABC
{
	char x;
	char y;
};

void fun_1()
{
    struct ABC a; struct ABC b;
    const struct ABC *ptr = &a;
    const struct ABC **qtr;

    qtr = &ptr; // This is valid
    *qtr = &b; // This is valid
    (**qtr).x = 'C'; // This is not valid
}

void fun_2()
{
    struct ABC a; struct ABC b;
    const struct ABC *ptr = &a;
    const struct ABC *const *qtr;

    qtr = &ptr; // This is valid
    *qtr = &b; // This is not valid
    (**qtr).x = 'C'; // This is not valid
}

void fun_3()
{
    struct ABC a; struct ABC b;
    const struct ABC *ptr = &a;
    const struct ABC *const *const qtr;

    qtr = &ptr; // This is not valid
    *qtr = &b; // This is not valid
    (**qtr).x = 'C'; // This is not valid
}

void fun_4()
{
    struct ABC a; struct ABC b;
    struct ABC *ptr = &a;
    struct ABC **const qtr = &ptr; // This is valid

    qtr = &ptr;// This is not valid
    *qtr = &b; // This is valid
    (**qtr).x = 'C'; // This is valid
}

void fun_5()
{
    struct ABC a; struct ABC b;
    struct ABC *ptr = &a;
    struct ABC *const *qtr = &ptr; // This is valid

    qtr = &ptr;// This is valid
    *qtr = &b; // This is not valid
    (**qtr).x = 'C'; // This is valid
}
const struct ABC **qtr; qtr, *qtr can be changed. **qtr can not be changed
const struct ABC *const *qtr; qtr can be changed. *qtr, **qtr can not be changed
const struct ABC *const *const qtr; qtr, *qtr, **qtr can not be changed
struct ABC **const qtr; *qtr, **qtr can be changed. qtr can not be changed
struct ABC *const *qtr; qtr, **qtr can be changed. *qtr can not be changed

const union double pointer

Description

#include <stdio.h>
#include <string.h>

union ABC
{
	char x;
	char y;
};

void fun_1()
{
    union ABC a; union ABC b;
    const union ABC *ptr = &a;
    const union ABC **qtr;

    qtr = &ptr; // This is valid
    *qtr = &b; // This is valid
    (**qtr).x = 'C'; // This is not valid
}

void fun_2()
{
    union ABC a; union ABC b;
    const union ABC *ptr = &a;
    const union ABC *const *qtr;

    qtr = &ptr; // This is valid
    *qtr = &b; // This is not valid
    (**qtr).x = 'C'; // This is not valid
}

void fun_3()
{
    union ABC a; union ABC b;
    const union ABC *ptr = &a;
    const union ABC *const *const qtr;

    qtr = &ptr; // This is not valid
    *qtr = &b; // This is not valid
    (**qtr).x = 'C'; // This is not valid
}

void fun_4()
{
    union ABC a; union ABC b;
    union ABC *ptr = &a;
    union ABC **const qtr = &ptr; // This is valid

    qtr = &ptr;// This is not valid
    *qtr = &b; // This is valid
    (**qtr).x = 'C'; // This is valid
}

void fun_5()
{
    union ABC a; union ABC b;
    union ABC *ptr = &a;
    union ABC *const *qtr = &ptr; // This is valid

    qtr = &ptr;// This is valid
    *qtr = &b; // This is not valid
    (**qtr).x = 'C'; // This is valid
}
const union ABC **qtr; qtr, *qtr can be changed. **qtr can not be changed
const union ABC *const *qtr; qtr can be changed. *qtr, **qtr can not be changed
const union ABC *const *const qtr; qtr, *qtr, **qtr can not be changed
union ABC **const qtr; *qtr, **qtr can be changed. qtr can not be changed
union ABC *const *qtr; qtr, **qtr can be changed. *qtr can not be changed