본문 바로가기
코스웨어/16년 스마트컨트롤러

20160308-허도경-업무일지-그 밖의 기초학습

by 알 수 없는 사용자 2016. 3. 9.
728x90
반응형

#include<stdio.h>

int main()

{

do

{

}While();//()안이 조건

return 0;

}

한번 실행하고 조건을 본다.

---------------------------------------------------------------------------------------------

while을 for문으로

(while문)

#incldue<stdio.h>

int main()

{

int iCnt;

iCnt = 1;

while(10>iCnt)

{

printf("3X%d=%d", iCnt, 3*iCnt);

iCnt = iCnt+1;

}

return 0;

}

(for문)

#include<stdio.h>

int main()

{

int iCnt

for(iCnt+1; 10>iCnt; iCnt = iCnt+1;)

{

printf("3X%d=%d", iCnt, 3*iCnt);

}

return 0;

}

------------------------------------------------------------------------------------

반복문(for문을 이용)

(무한반복문)

#include<stdio.h>

int main()

for( ; ; ) = while(1)

{

for(iCnt = 0; 100000000>iCnt; iCnt=iCnt+1)//iCnt=iCnt+1 = ++iCnt, iCnt++

{}

printf("test\n");

}

(지연반복문)

#include<stdio.h>

int main()

{

volatile int iCnt;

for( ; ; )

{

for (iCnt=0; 100000000>iCnt; iCnt= iCnt+1)

{}

printf("test\n");

}
return 0;

}

---------------------------------------------------------------------------------------------------------

위의 iCnt=iCnt+1 = ++iCnt, iCnt++에 대하여


++iCnt->iCnt=iCnt+1; A=iCnt->iCnt가 아직 결정되지 않았지만 +1을 한다.A가 100이것이 iCnt에 들어가 +1한 101을 A가 가지게된다.

iCnt++->A=iCnt; iCnt=iCnt+1->A가 100을가진다 그다음 +1을 한다.

(여기부분 갑자기 잘 기억이 안나네요)

---------------------------------------------------------------------------------------------------------

유니온과 스트럭트



#include<smart.h>                                                                                    

struct smart                                                                                           

{

int A;

short B;

int C;

char D;

}

int main()

{

printf("size of smart:%d\n", sizeof(struct smart);

return 0;

}

#include<smart.h>

union smart

{

int A;

short B;

int C;

char D;

}

int main()

{

union smart obj;

obj.A=0x12345678;

obj.B=0x12345678;

obj.C=0x12345678;

obj.D=0x12345678;

printf("size of smart:%d\n", sizeof(union smart);

printf("A=[%X]\n",obj.A);

printf("B=[%X]\n",obj.B);

printf("C=[%X]\n",obj.C);

printf("D=[%X]\n",obj.D);

return 0;

}


size of smart:16

 size of smart:4

A=12345678

B=5678

C=12345678

D=78




78

56 

34

12


obj.A=12345678->int형(4byte)
obj.B=5678->short형(2byte)
obj.C=12345678->int형(4byte)
obj.D=78->char형(1byte)


728x90