第16周项目2--用指针玩字符串(统计字符串长度)

2015-01-24 09:21:54 · 作者: · 浏览: 8
/* 
* Copyright (c) 2014, 烟台大学计算机学院 
* All rights reserved. 
* 文件名称:test.cpp 
* 作    者:刘畅 
* 完成日期:2014 年 12  月  11  日 
* 版 本 号:v1.0 
* 
* 问题描述:用指针作形参,其核心是实现int (char str[])函数。; 
* 输入描述:无需输入; 
* 程序输出:输出要求输出的。

(1)用数组名作行参;

#include 
  
   
using namespace std;
int astrlen(char str[]);
int main()
{
    char s1[50]="Hello world. ";
    char s2[50]="Good morning. ";
    char s3[50]="vagetable bird! ";
    cout<
   
    (2)用指针作行参;
    

#include 
     
      
using namespace std;
int astrlen(char *str);
int main()
{
    char s1[50]="Hello world. ";
    char s2[50]="Good morning. ";
    char s3[50]="vagetable bird! ";
    cout<
      
       
运行结果: