zoukankan      html  css  js  c++  java
  • C语言函数二维数组传递方法

    方法一:形参给出第二维的长度。

    例如:

    #include<stdio.h>
    #include
    <math.h>
    #include
    <ctype.h>
    #include
    <string.h>
    #include
    <stdlib.h>


    void func(int n,char str[][5]){
        
    int i;
        
    for(i=0; i<n; i++)
          printf(
    "\nstr[%d]=%s\n",i,str[i]);
        }

    int main()
    {
      
    char* p[3];
      
    char str[][5]={"abc","def","ghi"};
      func(
    3,str);
      
    return 0;

    }

     方法二:形参声明为指向数组的指针。

    例如:

     #include<stdio.h>

    #include<math.h>
    #include
    <ctype.h>
    #include
    <string.h>
    #include
    <stdlib.h>
    void func(int n,char (*str)[5]){
        
    int i;
        
    for(i=0; i<n; i++)
          printf(
    "\nstr[%d]=%s\n",i,str[i]);
        }
    int main()
    {
      
    char* p[3];
      
    char str[][5]={"abc","def","ghi"};
      func(
    3,str);
      
    return 0;
    }

    方法三:形参声明为指针的指针。

    例如:

     #include<stdio.h>

    #include<math.h>
    #include
    <ctype.h>
    #include
    <string.h>
    #include
    <stdlib.h>
    void func(int n,char **str){
        
    int i;
        
    for(i=0; i<n; i++)
          printf(
    "\nstr[%d]=%s\n",i,str[i]);
        }

    int main()
    {
      
    char* p[3];
      
    char str[][5]={"abc","def","ghi"};
      p[
    0]=&str[0][0];
      p[
    1]=str[1];
      p[
    2]=str[2];
      func(
    3,p);
      
    return 0;
    }
  • 相关阅读:
    通配符^与not like 区别
    SQL语句
    身份证的性别验证(摘抄)
    基于VirtualBox虚拟机安装Ubuntu教程
    VMware手动添加centos7硬盘图文操作及分区超详细
    acl权限命令
    linux查看分区是否开启acl权限
    CentOS7上Docker简单安装及nginx部署
    Docker安装ngnix使用ping报错
    centos7安装mysql5.6
  • 原文地址:https://www.cnblogs.com/xueda120/p/3068195.html
Copyright © 2011-2022 走看看