Skip to content

Instantly share code, notes, and snippets.

@pjastr
Last active April 24, 2020 06:11
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save pjastr/4ac29959e212436807c626610cb1b964 to your computer and use it in GitHub Desktop.
Save pjastr/4ac29959e212436807c626610cb1b964 to your computer and use it in GitHub Desktop.

Kod 1

#include <stdio.h>
#include <stdlib.h>

int main()
{
    int tab[2][3];
    for(int i=0;i<2;i++)
    {
        for(int j=0;j<3;j++)
        {
            printf("TAB[%d, %d]= ",i,j);
            scanf("%d",&tab[i][j]);
            printf("%p \n",&tab[i][j]);
        }
    }
    return 0;
}

Kod 2

#include <stdio.h>
#include <stdlib.h>

int main()
{
    int tab[2][3];
    for(int i=0;i<2;i++)
    {
        for(int j=0;j<3;j++)
        {
            printf("TAB[%d, %d]= ",i,j);
            scanf("%d",*(tab+i)+j);
            printf("%p \n",&tab[i][j]);
        }
    }
    return 0;
}

Kod3

#include <stdio.h>
#include <stdlib.h>

int main()
{
    int tab[2][3];
    int (*wsk_w)[3]; //wskaznik na wiersz (czyli 3 elementową tablice int)
    int*wsk_k; // wskaznik na kolumne (czyli na liczbę int)
    for(wsk_w = tab;wsk_w < tab + 2;wsk_w++)
    {
        for(wsk_k = *wsk_w;wsk_k < *wsk_w + 3;wsk_k++)
        {
            printf("TAB[%d, %d]= ",wsk_w-tab, wsk_k-*wsk_w);
            scanf("%d",wsk_k);
            printf("%p \n",wsk_k);
        }
    }
    return 0;
}

Kod 4

#include <stdio.h>
#include <stdlib.h>

int main()
{
    int tab[2][3];
    tab[ 0 ][ 0 ] = 5;
    **tab=7;
    return 0;
}

Kod 5

#include <stdio.h>
#include <stdlib.h>

int main()
{
    int**tabD = malloc(4*sizeof(int*));
    for(int i=0;i<4;i++)  // for(int i=0;i<4;i++)
    {
        *(tabD+i) = malloc(5*sizeof(int)); // tabD[i] = malloc(5*sizeof(int));
    }
    *(*(tabD+2)+3) = 111;   // tabD[2][3] = 111;
    //zamiana miejscami wierszy o indeksach 1 i 3
    int* wsk_pom;
    wsk_pom = *(tabD +1); // wsk_pom = tabD[0];
    *(tabD + 1) = *(tabD + 3); // tabD[0] = tabD[3];
    *(tabD + 3) = wsk_pom; // tabD[3] = wsk_pom;
    return 0;
}

Źródło: http://marek.piasecki.staff.iiar.pwr.wroc.pl/dydaktyka/skp/W11_wskazniki_na_tablice_wielowymiarowe_i_funkcje.pdf

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment