2015.09.08 C++笔记

#include <iostream>
#include <string>
using namespace std;


int *f1(int *i)
{
    ++(*i);
    return i;
}

int *f2(int *i)
{
    return i;
}

void f3(int *i, int *j)
{
    cout << *i <<" "<< *j <<endl;
}

int main(void)
{
    //04.sizeof again
    int c[10]; int *u = c;
    cout<<sizeof(u)<<" "<<sizeof(*u)<<" "<<sizeof(c)<<" "<<sizeof(*c)<<endl;
    //The result is: 4 4 40 4

    //03.求值顺序
    int k =0, j = 0;
    f3(f2(&j),f1(&j));  //无论先后顺序都会输出:1 1
    while (k < 21)
        cout <<++k<<" "<<k<<endl; //无论先后顺序都会输出:1 1
    
    //01.读入一行字符,将其中每个单词的首字母转化为大写,使用迭代器实现
    string s;
    int i = 0;
    getline(cin, s);
    for (auto b = s.begin(); b!=s.end(); b++)
    {
        if (isspace(*b))
            i = 0;
        else if (i == 0)
        {
            *b = toupper(*b);
            i = 1;
        }
        else i = 1;
    }
    cout<<"\n"<<s<<endl;

    //02.将数组中每个元素初始化为自身序号,size_t = unsinged int
    const int c1 = 3, c2 = 4; 
    int a[c1][c2];
    for ( i = 0; i<c1; i++ )
    {
        for (int j = 0; j<c2; j++ )
        {
            a[i][j] = i*c2 + j;
            cout<<a[i][j]<<' ';
        }
        cout<<endl;
    }

    getchar();

}
 

 

posted @ 2015-09-09 18:34  王爪爪  阅读(124)  评论(0编辑  收藏  举报