堆栈 Objective-C NSString copy strong
C
#include <stdio.h> #include <stdlib.h> int givar = 0; static int sgivar = 0; const int gcivar = 0; int main(int argc, char const *argv[]) { int ivar = 0; const int gcivar_2 = 0; char cvar = 'a'; char *string = "hello world"; char *pa = string; char *pb = string; int *pgi = &givar; int *psgi = &sgivar; int *pi = &ivar; int *pmivar = (int *)malloc(sizeof(int));//m -> malloc char *pc = &cvar; const int *pgcivar = &gcivar; const int *pgcivar_2 = &gcivar_2; printf("string: %p, %p\n", string, &string); printf("pa: %p, %p\n", pa, &pa); printf("pb: %p, %p\n", pb, &pb); printf("pgi:%p, %p\n", pgi, &pgi); printf("psgi:%p, %p\n", psgi, &psgi); printf("pi:%p, %p\n", pi, &pi); printf("pc:%p, %p\n", pc, &pc); printf("pmivar:%p, %p\n", pmivar, &pmivar); printf("pgcivar:%p, %p\n", pgcivar, &pgcivar); printf("pgcivar_2:%p, %p\n", pgcivar_2, &pgcivar_2); free(pmivar); return 0; }
分析如下:
Objective-C
http://www.cocoachina.com/ios/20150512/11805.html