两个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;
}


你可能感兴趣的:(sizeof)