C language2010. 6. 10. 15:51

#include <stdio.h>

int strlen2(const char *p);

int main()
{
int inum;
inum = strlen2("test");
printf("%d",inum);


return 0;
}


int strlen2(const char *p)
{
int icnt;


for(icnt = 0;*p !=0;++icnt)
{
++p;
}

return icnt;

}

실행결과




heap,stack영역에 대한설명

#include <stdio.h>
#include <malloc.h>

int main()
{
char *p;
int *d;
d = malloc(100);

printf("P의 주소%p\t\n", &p);
printf("main의 주소%p\t\n", main);
printf("printf의 주소%p\t\n", printf);
printf("malloc의 주소%p\t\n", d);
printf("문자열의 주소%p\t\n", "abc");

return 0;
}


메모리영역에 대한 설명


동적할당을 받은 메모리의 주소를 포인터 변수에 저장하고 동적할당을 받은 메모리를 반환한다.

이 때 , 동적할당을 받았을 때 저장했던 주소에 값을 다시 쓸 수 있을까??

정답은 쓸 수 있다이다. 다만 오류가 날 수도 있다.

'C language' 카테고리의 다른 글

2차원배열을 이용,배열원소의 합구하는 프로그램  (0) 2010.06.19
Posted by 해해해해해해해해