본문 바로가기

C언어

2010년 11월 19일 금요일 int 보다 unsigned int가 속도가 더 빠르다. int는 부호확장 검사를 하기 때문에 부호확장 검사를 안하는 unsigned int가 상대적으로 더 빠를수 밖에 없다. #typedef unsigned int unint 더보기
sizeof 연산자로 배열의 행과 열 크기를 알아내는 팁 int main(int argc, char **argv) { int a[5][10]; printf("rows : %d\n",sizeof(a)/sizeof(a[0])); printf("cols : %d\n", sizeof(a[0])/sizeof(int)); return 0; } 실행결과 $ ./sizeof rows : 5 cols : 10 더보기
Hex뷰어 소스 #include void PrintHexaNAscii(const unsigned char *buffer, int size); int main() { int a = 0xffffffff; PrintHexaNAscii((unsigned char *)&a, 100); return 0; } void PrintHexaNAscii(const unsigned char *buffer, int size) { int count1; int count2; const unsigned char *temp=buffer; printf(" Address "); for(count1=0; count1 더보기
달팽이배열 알고리즘 위의 그림과 같이 1부터 순서대로 수를 적어 넣는 달팽이 배열이다. #include int main() { int start=0; int count=0; int count2; int X=0; int Y=0; int XH; int YH; int XL=0; int YL=0; int area[10][10]={0}; int height; int width; printf("X, Y좌표를 입력하시오 : "); scanf("%d %d", &height, &width); XH = height-1; YH = width-1; for(count=0; height*width>count; count++) { area[Y][X]=count+1; switch(start) { case 0 : X++; if(XH==X) { start.. 더보기
2010년 11월 15일 월요일 (배열과 포인터) int iarray[]={3,1,2,8,4}; // 상수열 char carray[]="test"; // 문자열 printf("%d\n", iarray[3]); // 8 출력 printf("%d\n", 3[iarray]); // 8 출력 printf("%d\n", *iarray); // iarray[0] printf("%d\n", *(iarray+2)); // 포인터 참조 printf("%d\n", iarray[3]); // 인덱스 참조printf("%d\n", [iarray]3); // 에러 더보기