スキップしてメイン コンテンツに移動

block1


double (^g)(double, double);
g = ^(double m, double n) { return a + b; };
// .. later
g = ^(double x, double y) { return x * y; }; // g reassigned to point to a new block; same type, so no problem
// but not:
// g = ^(int x) { return x + 1; }; // types are different! The literal on the right has type int(^)(int), not double(^) (double, double)!
double (^h)(double, double) = g; // no problem here! h has the correct type and can be made to point to the same block as g
// compare with:
int i = 10, j = 11; // declaring a coupling of integers
int *ptrToInt; // declaring a pointer to integers
ptrToInt = &i; // ptrToInt points to i
// later...
ptrToInt = &l // ptrToInt now points to j
float f = 3.14;
// ptrToInt = &f; // types are different! technically can be done, but compiler will warn you of the type difference. And typically you don't want to do this!
int *anotherPtrToInt;
anotherPtrToInt = ptrToInt; // both pointers point to the same integer's location in memory

コメント

このブログの人気の投稿

日本に来た 今三週間

四月六日に日本に来た、今三週間になった。 嬉しくなかった、悲しくなかった。 日本の携帯電話のカメラはとてもいいよ、私は今撮影が好きだ、いつも寮に帰る途中で花とか魚とか写真を撮る。これも生活の趣味だ。 滴は綺麗だ 桜が凋んで落ちる 天気がいいとき、自転車に乗って、食材を買った。 自分で料理をつくる、おいしそうでしょう。 昨日清水寺に行った、天気はとても熱いね。日に焼けすぎたので、腕は今赤い。 側に花があるので、赤い清水寺はもっと美しそうだ。 木の色は艶やかだ。