분류 | 게시판 |
베스트 |
|
유머 |
|
이야기 |
|
이슈 |
|
생활 |
|
취미 |
|
학술 |
|
방송연예 |
|
방송프로그램 |
|
디지털 |
|
스포츠 |
|
야구팀 |
|
게임1 |
|
게임2 |
|
기타 |
|
운영 |
|
임시게시판 |
|
#include <stdio.h> #include <string.h> int main() { { char *str1 = "hello!"; char *str2; printf("str1(%d): %s\\n", strlen(str1), str1); str2 = str1; printf("str2(%d): %s\\n", strlen(str2), str2); printf("please input a character -> "); // *str2 = getchar(); // Segmentation fault here printf("modified str2(%d): %s\\n", strlen(str2), str2); }printf("\\n"); { int a = 65; char *b = &"ABC"; int *c = &"ABC"; printf("a=0x%x, *b=0x%x, *c=0x%x\\n", a, *b, *c); printf("&a=0x%x, b=0x%x, c=0x%x\\n", &a, b, c); printf("&\\"ABC\\" is 0x%x\\n", &"ABC"); printf("int value of \\"ABC\\" is 0x%x\\n", *((int *)&"ABC")); }printf("\\n"); { typedef struct { char a; char b; int c; } user_unpacked_type; #pragma pack(push, 1); typedef struct { char a; char b; int c; } user_type; #pragma pop(); printf("size of user_unpacked_type is %d\\n", sizeof(user_unpacked_type)); printf("size of user_type is %d\\n", sizeof(user_type)); { int i; user_type ut = {'A', 'B', *((int *)&"CDE")}; for(i=0; i<sizeof(user_type); i++) printf("ut[%d] is 0x%x\\n", i, ((char *)&ut)[i]); printf("or otherwise....\n"); for(i=0; i<sizeof(user_type)-sizeof(int); i++) printf("ut[%d] is 0x%x\\n", i, ((int *)&ut)[i]); } }printf("\\n"); { unsigned int a = 1234567890; int b = *((int *)&a); char c = *((char *)&a); long d = *((long *)&a); printf("a = 0x%x\\n", a); printf("b = 0x%x\\n", b); printf("c = 0x%x\\n", c); printf("d = 0x%x\\n", d); }printf("\\n"); return 0; } |
// first running str1(6): hello! str2(6): hello! please input a character -> modified str2(6): hello! a=0x41, *b=0x41, *c=0x434241 &a=0x1ae753b0, b=0x4009c7, c=0x4009c7 &"ABC" is 0x4009c7 int value of "ABC" is 0x434241 size of user_unpacked_type is 8 size of user_type is 6 ut[0] is 0x41 ut[1] is 0x42 ut[2] is 0x43 ut[3] is 0x44 ut[4] is 0x45 ut[5] is 0x0 or otherwise.... ut[0] is 0x44434241 ut[1] is 0x45 a = 0x499602d2 b = 0x499602d2 c = 0xffffffd2 d = 0x499602d2 // second running str1(6): hello! str2(6): hello! please input a character -> modified str2(6): hello! a=0x41, *b=0x41, *c=0x434241 &a=0xd94056b0, b=0x4009c7, c=0x4009c7 &"ABC" is 0x4009c7 int value of "ABC" is 0x434241 size of user_unpacked_type is 8 size of user_type is 6 ut[0] is 0x41 ut[1] is 0x42 ut[2] is 0x43 ut[3] is 0x44 ut[4] is 0x45 ut[5] is 0x0 or otherwise.... ut[0] is 0x44434241 ut[1] is 0x45 a = 0x499602d2 b = 0x499602d2 c = 0xffffffd2 d = 0x499602d2 |
죄송합니다. 댓글 작성은 회원만 가능합니다.
번호 | 제 목 | 이름 | 날짜 | 조회 | 추천 | |||||
---|---|---|---|---|---|---|---|---|---|---|
440 | 이거 환불 되나요? [3] | 잠이오네요 | 15/09/04 09:33 | 390 | 5 | |||||
439 | 저도 다이아 한번... [2] | 잠이오네요 | 15/08/21 15:44 | 64 | 0 | |||||
438 | iOS9은 모바일 웹 광고차단 기능이 기본 탑재된다네요 [2] | 잠이오네요 | 15/08/15 15:17 | 72 | 5 | |||||
437 | 자택 근무도 썩 좋진 않네요 + 자택근무자 분들에게 질문 [11] | 잠이오네요 | 15/08/12 05:32 | 90 | 0 | |||||
436 | 자취방을 구하고 있는데 조언 부탁드립니다 [1] | 잠이오네요 | 15/07/10 13:23 | 29 | 0 | |||||
435 | 왜 냉면일까요 [10] | 잠이오네요 | 15/06/14 19:02 | 89 | 10 | |||||
434 | 메르스? 우린 젊어서 걸려도 그냥 감기처럼 지나가잖아? [9] | 잠이오네요 | 15/06/12 23:00 | 492 | 11 | |||||
433 | 다수결은 민주주의가 아닙니다 [1] | 잠이오네요 | 15/06/07 10:08 | 80 | 0 | |||||
432 | 부산의 흔한 다리 진입로 [1] | 잠이오네요 | 15/04/21 18:46 | 149 | 3 | |||||
431 | 애플워치 골드 에디션 도금 아니었네요ㄷ; [6] | 잠이오네요 | 15/03/23 03:44 | 128 | 5 | |||||
430 | 아이폰6/6+ 출시가 보고 통신사 구매 망설이시는 분을 위한 안내 [5] | 잠이오네요 | 14/10/15 12:16 | 187 | 5 | |||||
429 | 피카소 [6] | 잠이오네요 | 14/10/07 12:55 | 555 | 12 | |||||
428 | 기술의 발전이 참 대단하네요 [4] | 잠이오네요 | 14/10/07 12:29 | 539 | 7 | |||||
427 | 팀국X아이폰 [3] | 잠이오네요 | 14/09/10 21:47 | 215 | 17 | |||||
426 | 잡스와 워즈니악이 사이가 나쁜 진짜 이유 [8] | 잠이오네요 | 14/07/23 10:41 | 110 | 10 | |||||
425 | 아래 전기자동차 글을 보고 [1] | 잠이오네요 | 14/07/18 11:24 | 47 | 0 | |||||
424 | 마우스랜드 | 잠이오네요 | 14/06/17 13:28 | 52 | 2 | |||||
423 | 혐짤 [2] | 잠이오네요 | 14/06/09 22:36 | 185 | 0 | |||||
422 | 최근 이삼일 먹은 템인데요, 마부 어떻게 하면 좋을까요? [3] | 잠이오네요 | 14/05/19 17:25 | 236 | 0 | |||||
421 | 요새 노조미 글이 자주 올라오는데 [1] | 잠이오네요 | 14/05/11 11:16 | 115 | 0 | |||||
420 | 세월호 침몰 당시 승무원 상태 추측글 [14] | 잠이오네요 | 14/04/21 16:23 | 925 | 12 | |||||
▶ | C언어 중수를 위한 포인터 예제 [1] | 잠이오네요 | 14/02/01 01:12 | 31 | 0 | |||||
418 | 초보자가 C언어 포인터에서 좌절하는 이유는 [1] | 잠이오네요 | 14/01/31 19:15 | 56 | 0 | |||||
417 | 특대 사이즈 카푸치노 [2] | 잠이오네요 | 14/01/21 13:57 | 197 | 2 | |||||
416 | 오늘의 아점 [1] | 잠이오네요 | 14/01/21 11:30 | 171 | 3 | |||||
415 | 웹 개발 주저리 | 잠이오네요 | 14/01/19 17:38 | 27 | 2 | |||||
414 | 모든 언어는 두 종류로 구분 가능합니다 [12] | 잠이오네요 | 14/01/15 13:17 | 117 | 1 | |||||
413 | 오늘의 야식 일기 - 돼지국밥 [2] | 잠이오네요 | 14/01/13 06:28 | 190 | 5 | |||||
412 | 간단하고 따뜻한 커피우유 | 잠이오네요 | 13/12/30 16:54 | 104 | 1 | |||||
411 | 시험기간이라 그런지 [1] | 잠이오네요 | 13/12/17 19:58 | 41 | 0 | |||||
|
||||||||||
[1] [2] [3] [4] [5] [6] [7] [8] [9] [10] [다음10개▶] | ||||||||||