변환 문자와 기호 문자는 printf문과 다른 함수에도 많이 사용되는 것이다. 변환 문자는 %를 사용한다.
%d -> int (정수)
%f -> float (실수; 0.1이여도 0.100000처럼 6자리로 강제로 늘린다)
%g -> float (실수; %f와 달리 0.1로 출력)
%c -> char (문자; 1개만)
%s -> string (문자열)
쓰임은 이렇다
printf("%d", 134); // output -> 134 printf("%f", 0.1); // output -> 0.100000 printf("%g", 0.1); // output -> 0.1 printf("%c", 'a'); // output -> a / -P.S. char -> '', string -> "" printf("%s", "hello"); // output -> hello
기호 문자는 printf문에서 줄바꿈이나 tab 키 등을 대신해 주는 문자다. \를 사용한다.
\n -> 줄바꿈
\t -> tab
\\ -> \
\" -> "
\' -> '
예외: %% -> %
이 외에도 많은 기호 문자들이 있다. 이 기호 문자들은 대표적으로 쓰이는 문자들이다.
소스코드:
printf("hello\n"); // output -> hello(enter key) printf("hello \t hello"); // output -> hello hello printf("\"hello\""); // output -> "hello" printf("\'hello\'"); // output -> 'hello' P.S. printf("'hello'"); is equal to \' because of updates. printf("5%%"); // output -> 5%
이정도만 설명하면 되겠네요