강의

멘토링

커뮤니티

Inflearn Community Q&A

1411245375's profile image
1411245375

asked

Learn C Programming by Following Along with Hong Jeong-mo

4.8 Modifiers of conversion specifiers

flag 개수

Written on

·

258

0

flag는 하나의 형식 지정자에 하나밖에 못쓰나요?
가령 "%-010i"를 활용했었는데요, 1234567이 있다고 가정하면 1234567000이 출력될 줄 알았는데 0은 따로 출력이 안되어서요!
c

Answer 1

0

안녕하세요 :)

이 링크를 확인해보시면 

여러 개의 플래그를 동시에 사용할 수 있는 것으로 보입니다.

 

가령 아래 코드의 경우

 

#include <stdio.h>

int main()
{
	printf("%#010x\n", 12);
	return 0;
}

 

결과는 0x0000000c 가 됩니다. 

 

제시하신 코드의 경우에도, 

아래와 같이 프린트 할 수 있습니다.

 

#include <stdio.h>

int main()
{
	printf("%i\n", 1234567);	// 1234567
	printf("%010i\n", 1234567); // 0001234567
	printf("%+010i\n", 1234567); // +001234567
		
	return 0;
}

 

감사합니다.

 

1411245375's profile image
1411245375

asked

Ask a question