zoukankan      html  css  js  c++  java
  • Multidimensional Arrays and pointer in C language

    char** argv == char* argv[]

    in int main(int argc, char* argv[])

    e,g:   

    int (* pz)[2]; //a pointer(pz) points to an array of 2 ints.
    
    int * pax[2]; // 2 pointers

    dynamic multi-dimensional arrays in C

    func(int x, int y, int a[x][y])
    	{
    	...
    	}
    

    where the array dimensions are specified by other parameters to the function? Unfortunately, in C, you cannot. (You can do so in FORTRAN, and you can do so in the extended language implemented by gcc, and you will be able to do so in the new version of the C Standard (``C9X'') to be completed in 1999, but you cannot do so in standard, portable C, today.)

    Finally, we might explicitly note that if we pass a multidimensional array to a function:

    	int a2[5][7];
    	func(a2);

     ------

    Dynamically Allocating Multidimensional Arrays

        #include <stdlib.h>
    
        int **array;
        array = malloc(nrows * sizeof(int *));
        if(array == NULL)
            {
            fprintf(stderr, "out of memory\n");
            exit or return
            }
        for(i = 0; i < nrows; i++)
            {
            array[i] = malloc(ncolumns * sizeof(int));
            if(array[i] == NULL)
                {
                fprintf(stderr, "out of memory\n");
                exit or return
                }
            }

    for(i = 0; i < nrows; i++)
            free(array[i]);
        free(array);
  • 相关阅读:
    进程控制(二)
    进程控制(一)
    python的signal
    python的logging模块
    python守护进程
    C语言关键字、标识符和注释
    青春代码
    冒泡排序 js
    数组
    js 运算符
  • 原文地址:https://www.cnblogs.com/bittorrent/p/2743040.html
Copyright © 2011-2022 走看看