Char

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

void fun(char str[100]);

void main()
{
    char c[] = {'a','b','c','d','e','\0'};
    char c1[] = {'a','b','c','d','e'};
    char c2[]="ab\0cd\n";
    string s = "ab\0cd\n";
    cout << c << "  " << sizeof(c) << endl;                   //abcde  6
    cout << c1 << "  " << sizeof(c1) << endl;               //abcde烫烫烫烫烫蘟bcde  5
    cout << c2 << "  " << sizeof(c2) << endl;               //ab  7
    cout << s << "  " << sizeof(s) << endl;                   //ab  32

    unsigned char * quan1 =  (unsigned char *) malloc(1000* sizeof(unsigned char));
    unsigned char * quan = NULL;
    quan = new unsigned char[10];
    quan[0] = '16\0';
    quan[1] = 16;
    printf("%d\n",quan[0]);                               //0
    printf("%d\n",quan[1]);                               //16
    cout << quan[0] << "  " << quan[1] << endl;
    cout << sizeof(quan[0]) << "  " << sizeof(quan[1]) << endl;            //1  1
    cout << sizeof(char) << "  " << sizeof(unsigned char) << endl;       //1  1
    cout << sizeof(int) << "  " << sizeof(long) <<endl;                           //4  4
    delete quan;

    char str[100];
    fun(str);

    system("pause");
}


void fun(char str[100])
{
    cout << "2014.03.24" << endl;
    char name[] = "C++ Game";
    char name1[100] = "C++ Game";
    cout << sizeof(str) << endl;                //4
    cout << sizeof(name) << endl;           //9
    cout << strlen(name) << endl;           //8
    cout << sizeof(name1) << endl;         //100
    cout << sizeof(char *) << endl;           //4
    cout << sizeof(char &) << endl;          //1
    cout << sizeof(short &) << endl;         //2
}

Char

 

转载于:https://my.oschina.net/ucliaohh/blog/806162