Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- //#define _GRIBCXX_DEBUG
- #include <bits/stdc++.h>
- # define rep(i, n) for (int i = 0; i < (int)(n); i++)
- using namespace std;
- template<typename integer>
- integer __lcm(integer a, integer b) {
- return (a * b) / __gcd(a, b);
- }
- void swap(int *a, int *b) {
- int x;
- x = *a;
- *a = *b;
- *b = x;
- }
- // 代入を使ってループをしてコピー
- void strcpy(char *s, char *t) {
- while (*s++ = *t++)
- ;
- }
- int main() {
- int a = 2;
- int b = 4;
- // swap の実装
- cout << a << "," << b << endl;
- // 引数がポインタ型のときは勝手にキャストされる?
- swap(a, b);
- swap(&a, &b);
- cout << a << "," << b << endl;
- // 配列をポインタで
- int c[3] = {1, 2, 3};
- // int *i = &c[0];
- // []がないと,配列の先頭要素へのポインタという意味になる
- int *i = c;
- cout << c << endl;
- cout << *i << endl;
- i++;
- cout << *i << endl;
- char d[] = "Sample string";
- char e[sizeof(d)];
- cout << "d: " << d << endl;
- cout << "e: " << e << endl;
- strcpy(e, d);
- // これがエラーになってしまうのはなぜ?
- // no matching function for call to 'strcpy(char (*)[14], char (*)[14])'
- // strcpy(&e, &d);
- cout << "e: " << e << endl;
- return 0;
- }
Add Comment
Please, Sign In to add comment