/*
version: 1.0
author: hellogiser
blog: http://www.cnblogs.com/hellogiser
date: 2014/6/3
*/
#include "stdafx.h"
#include <iostream>
using namespace std;
])
{
// when a is passed to function,a will become a array pointer
// like int (*p)[3], so sizeof(a)==4
cout << sizeof(a) << endl; // 4
}
void test_2dim()
{
// array pointer
};
];
p = a;
fun(a);
// test sizeof
// for a
cout << sizeof(a) << endl; // 24
) << endl; // 4 (24 in debug local watch)
) << endl; // 4 (24 in debug local watch)
cout << ]) << endl; // 12
]) << endl; // 12
)) << endl; // 12
)) << endl; // 12
]) << endl; // 4
// for p
cout << sizeof(p) << endl; // 4
) << endl; // 4
) << endl; // 4
cout << ]) << endl; // 12
]) << endl; // 12
)) << endl; // 12
)) << endl; // 12
]) << endl; // 4
// pointer array
];
;
;
r[] = &i;
r[] = &j;
cout << sizeof(r) << endl; // 8
}
void test_1dim()
{
};
int *p = a;
int *p1 = (int *)&a;
);
]; // array pointer
b = &a;
int *b1 = (int *)b;
);
cout << "ok" << endl;
}
void test_string()
{
char *str1 = "abcd";
char str2[] = "1234";
cout << str1 << endl; // abcd
cout << str2 << endl; // 1234
cout << *str1 << endl; // a
cout << *str2 << endl; // 1
//str1[0]='X'; // ERROR
] = 'Y'; // right
cout << *str2 << endl; // Y
}
void funstr(char str[])
{
printf("After transform:%d\n", sizeof(str)); //4
}
void test_array_as_param()
{
char strs[] = "abcdefg";
printf("Before transform:%d\n", sizeof(strs)); //8
funstr(strs);
}
void test_a()
{
// (int&)a treat a memory as a integer
.0f;
cout << (int)a << endl; // 1
cout << (int &)a << endl; // 1065353216
cout << boolalpha << ( (int)a == (int &)a ) << endl; // false
.0f;
cout << (int)b << endl; // 0
cout << (int &)b << endl; // 0
cout << boolalpha << ( (int)b == (int &)b ) << endl; // true
}