两个sizeof用法

#include <iostream>
using namespace std;

void UpperCase( char str[] ) // 将 str 中的小写字母转换成大写字母
{
    for( int i=0; i<sizeof(str)/sizeof(str[0]); ++i )
        if( 'a'<=str[i] && str[i]<='z' )
            str[i] -= ('a'-'A' );
}

int main()
{
	char str[] = "aBcDe";
	cout<< "str字符长度为: " << sizeof(str)/sizeof(str[0]) <<endl;
	UpperCase( str );
	cout<<str<< endl; 
	cout<<"sizeof(“zhangdongsheng”)"<<sizeof("zhangdongsheng")<<endl;
	cout<<"strlen(“zhangdongsheng”)"<<strlen("zhangdongsheng")<<endl;
	char str2[]="zhangdongsheng";
	UpperCase(str2);
	cout<<str2<<endl;
	
	return 0;
}


posted @ 2010-10-27 11:49  瓜蛋  阅读(353)  评论(0编辑  收藏  举报