zoukankan      html  css  js  c++  java
  • c语言调用函数打印一维数组-2-指针

    方法一(规范):
     1 #include <stdio.h>
     2 #include <math.h>
     3 #include <stdlib.h>
     4 
     5 //函数预声明
     6 void printVector(double(*p)[3], int m);//向量的打印
     7 //主函数
     8 int main(void)
     9 {
    10 
    11     double uk0[3] = { 1.0, 2.0, 3.0 };//迭代向量
    12     double(*puk0)[3] = &uk0;//迭代向量指针 &uk0 是整个数组的首地址,uk0是数组首元素的首地址    
    13     printf("初始向量u0:
    ");
    14     printVector(puk0, 3);
    15     system("pause");
    16 }
    17 
    18 //函数具体执行
    19 //向量的打印
    20 void printVector(double(*p)[3], int m)
    21 {
    22     for (int i = 0; i < m; i++)
    23     {
    24         printf("%lf  ", (*p)[i]);
    25     }
    26 }

    方法二(写着简单):

     1 #include <stdio.h>
     2 #include <math.h>
     3 #include <stdlib.h>
     4 
     5 //函数预声明
     6 void printVector(double *p, int m);//向量的打印
     7 //主函数
     8 int main(void)
     9 {
    10 
    11     double uk0[3] = { 1.0, 2.0, 3.0 };//迭代向量
    12     double *puk0 = uk0;//迭代向量指针 &uk0 是整个数组的首地址,uk0是数组首元素的首地址    
    13     printf("初始向量u0:
    ");
    14     printVector(puk0, 3);
    15     system("pause");
    16 }
    17 
    18 //函数具体执行
    19 //向量的打印
    20 void printVector(double *p, int m)
    21 {
    22     for (int i = 0; i < m; i++)
    23     {
    24         printf("%lf  ", p[i]);
    25     }
    26 }
  • 相关阅读:
    SQL注入过滤
    ASP.NET长文章分页
    简单的权限管理类
    不错的面试题
    【转载】【重要】Ubuntu Linux 下 Ffmpeg 及 Mencoder 安装使用小结
    回到xwindows
    suse11 linux不自动启动xwindows
    flash的几种工具
    mencoder和ffmpeg参数详解
    ffmpeg和Mencoder使用实例小全
  • 原文地址:https://www.cnblogs.com/zhubinglong/p/5982622.html
Copyright © 2011-2022 走看看