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

20160406_장진웅_업무일지_로봇제어_시리얼제어3

by 알 수 없는 사용자 2016. 4. 6.
728x90
반응형

const char *P = "Test"; ("Test" = const char *)

char const *P = "Test"; <- 이렇게 적어도 위와 동일하다.

↑위의 const는 *를 가리킨다.


char * const P = "Test";

↑위의 const는 P를 가리킨다.



#include <stdio.h>

int main(void)

{
     char * P1 = "Test";
     const char * P2 = "Test";
     char const * P3 = "Test";
     char * const P4 = "Test";
     const char * const P5 = "Test";
     char const * const P6 = "Test";

     printf("P1=[%s], [%p] \n", P1, P1);
     printf("P2=[%s], [%p] \n", P2, P2);
     printf("P3=[%s], [%p] \n", P3, P3);
     printf("P4=[%s], [%p] \n", P4, P4);
     printf("P5=[%s], [%p] \n", P5, P5);
     printf("P6=[%s], [%p] \n", P6, P6);

     printf(P1 = "Zest \n");
     printf(P2 = "Zest \n");
     printf(P3 = "Zest \n");
 //    printf(P4 = "Zest \n");
 //    printf(P5= "Zest \n");
 //    printf(P6= "Zest \n");
     return 0;
}


<출력결과 CL>


<출력결과 Visual Studio 2015>


<출력결과 Linux>


즉, const가 어디에서 컴파일 하느냐에 따라 위치가 달라진다.



1. 배열에 1Kilo byte(KB)를 집어 넣고 싶으면 

ex) *char caText[1024];를 넣어주면 된다.

2. 배열에 1Mega byte(MB)를 집어 넣고 싶으면 

ex) *char caText[1024*1024];를 넣어주면 된다.

3. 배열에 1Giga byte(GB)를 집어 넣고 싶으면 

ex) *char caText[1024*1024*1024];를 넣어주면 된다.






열혈 C프로그래밍(397page) 추가 예제) 형(Type)이 존재하지 않는 void 포인터

 #include <stdio.h>

 int main(void)
 {
     char A=1;
     short B=10;
     int C=100;
     void *vp;

     printf("캐릭터 A: %d \n", A);
     printf("쇼트 B: %d \n", B);
     printf("인트 C: %d \n\n", C);

     vp=&A;
     printf("캐릭터 vp: %d \n", *((char *)vp));
     vp=&B;
     printf("쇼트  vp: %d \n", *((short *)vp));
     vp=&C;
     printf("인트  vp: %d \n", *((int *)vp));

     // B=*vp;


     return 0;
 }
  

<출력결과>


열혈 C프로그래밍(401page)

1
2
3
4
5
6
7
8
9
10
11
 #include <stdio.h>

 int main(int argc, char *argv[])
 {
     int i=0;
     printf("전달된 문자열의 수: %d \n", argc);

     for(i=0; i<argc; i++)
         printf("%d번째 문자열: %s \n", i+1, argv[i]);
     return 0;
 }

<출력결과 in DOS>

<출력결과 in Linux>


printf의 진실

 #include <stdio.h>

 int main(void)
 {
     fprintf(stdout ,"Hello World!");
     return 0;
 }


printf는  fprintf(stdout ,"Hello World!");에게 하도급을 주는 것이다.


728x90