본문바로가기

 C 언어 자료형과 Print format

 개발관련  2015. 2. 11. 20:46  창조컨서턴트

Microsoft Visual C++ recognizes the types shown in the table below.
Type NameBytesOther NamesRange of Values
int*signed, 
signed int
System dependent
unsigned int*unsignedSystem dependent
__int81char, 
signed char
–128 to 127
__int162short, 
short int, 
signed short int
–32,768 to 32,767
__int324signed, 
signed int
–2,147,483,648 to 2,147,483,647
__int648none–9,223,372,036,854,775,808 to 9,223,372,036,854,775,807
bool1nonefalse or true
char1signed char–128 to 127
unsigned char1none0 to 255
short2short int, 
signed short int
–32,768 to 32,767
unsigned short2unsigned short int0 to 65,535
long4long int, 
signed long int
–2,147,483,648 to 2,147,483,647
long long8none (but equivalent to __int64)–9,223,372,036,854,775,808 to 9,223,372,036,854,775,807
unsigned long4unsigned long int0 to 4,294,967,295
enum*noneSame as int
float4none3.4E +/- 38 (7 digits)
double8none1.7E +/- 308 (15 digits)
long doublesame as doublenonesame as double
wchar_t2__wchar_t0 to 65,535
A variable of __wchar_t designates a wide-character or multibyte character type. By default wchar_t is a typedef for unsigned short.

 
Sizes of Fundamental Types
TypeSize
bool1 byte
charunsigned charsigned char1 byte
shortunsigned short2 bytes
intunsigned int4 bytes
__intn1, 2, 4, or 8 bytes depending on the value of n. __intn is Microsoft-specific.
longunsigned long4 bytes
float4 bytes
double8 bytes
long double18 bytes
long longEquivalent to __int64.
1   The representation of long double and double is identical. However, long double and double are separate types.

ype (형)

인수의 형을 지정

dint값을 부호있는 10진수로 출력
id와 같음
uint값을 부호없는 10진수로 출력
Xint값을 부호없는 16진수로 출력  10~15은  'A'~'F'로 표시
xint값을 부호없는 16진수로 출력  10~15은  'a'~'f'로 표시
oint값을 부호없는 8진수로 출력
p포인터값을 16진수로 출력
s문자열 출력
cint값을 문자로 출력
Cc와 같음
fdouble값을 소수로 출력 (예:12.566371)
edouble값을 지수로 출력 (예:1.256637e+001)
Ee와 같음 'e'가 'E'로 표시 (예:1.256637E+001)。
g숫자값의 크기에 따라 f나 e로 출력  (예:12.5664、2.99792e+008)
숫자값의 절대치가 너무 커서 precision의 자리수를 넘는 경우와 숫자값의 절대값이 0.0001보다 작은 경우 e형식이 사용되어짐. 그 외의 경우는 f형식으로 사용됨
G9와 같음 'e'가 'E'로 표시

type long long
printf("%llu", 285212672);
   printf("the unsigned int is %u\n\n",a);

   printf("the float number is %g, and %G\n\n",b,b);

   printf("RAY%n\n\n",&c);

   printf("last line prints %d characters\n\n",c);

   printf("Address of d is %p\n\n",d);

   printf("%d   %+d    %06d     %X    %x     %o\n\n",
      count, count, count, count, count, count);

   printf("1234567890123%n4567890123456789\n\n", &count);

   printf("Value of count should be 13; count = %d\n\n", count);

   printf("%10c%5c\n\n", ch, ch);

   printf("%25s\n%25.4s\n\n", string, string);

   printf("%f    %.2f    %e    %E\n\n", fp, fp, fp, fp);

   printf("%i    %i     %i\n\n", hex, oct, dec);
the unsigned int is 12

the float number is 123.45 and 123.45

RAY

last line prints 3 characters

Address of d is DD72F9

234   +234    000234     EA    ea     352

12345678901234567890123456789

Value of count should be 13; count = 13

         h    h

                 computer
                     comp

251.736600    251.74    2.517366e+02    2.517366E+02

16    8     10
  printf("pd01 %%D(10,2)      = %D(10,2)\n", pd01);
  printf("pd02 %%D( 12 , 4 )  = %D( 12 , 4 )\n", pd02);

  printf("pd01 %%010.2D(10,2) = %010.2D(10,2)\n", pd01);
  printf("pd02 %%20.2D(12,4)  = %20.2D(12,4)\n", pd02);
  printf("\n Give strange result if the specified size is wrong!\n");
  printf("pd03 %%D(15,3)      = %D(15,3)\n\n", pd03);
pd01 %D(10,2)      = -12.34
pd02 %D( 12 , 4 )  = 12345678.9876
pd01 %010.2D(10,2) = -000012.34
pd02 %20.2D(12,4)  =          12345678.98

Give strange result if the specified size is wrong!
pd03 %D(15,3)      = -123456789013.579
   c = 'l';
   i = 35;
   fp = 1.7320508;

   /* Format and print various data */
   j = sprintf(buffer, "%s\n", s);
   j += sprintf(buffer+j, "%c\n", c);
   j += sprintf(buffer+j, "%d\n", i);
   j += sprintf(buffer+j, "%f\n", fp);
   printf("string:\n%s\ncharacter count = %d\n", buff);
string:
baltimore
l
35
1.732051

character count = 24