• 【转】objective-c基本数据类型之输出格式符


    原文网址:http://blog.csdn.net/mamong/article/details/8255691

    基本数据类型

    1. int

    输出格式符:%i, %d, %o %x, 

    2. float
    输出格式符:%f, %e, %g

    3. double
    输出格式符:%f, %e, %g
     

    4. char

    输出格式符:%c

    限定符:


    1. long
    long int: %li
    long double: %Lf
    形成long int通过在数字后面加L.
    long int number = 123324123234123L;

    2. long long
    long long int: %lli

    3. short
    short int: %hi

    4. unsigned

    5. signed

    它们各自所占的字节数

    #import <Foundation/Foundation.h>

    int main (int argc, const char * argv[]) {

        NSAutoreleasePool * pool = [[NSAutoreleasePool alloc] init];

    NSLog(@"The size of an int is: %d bytes.",sizeof(int));

    NSLog(@"The size of a short int is: %d bytes.",sizeof(short int));

    NSLog(@"The size of a long int is: %d bytes.",sizeof(long int));

    NSLog(@"The size of a char is: %d bytes.",sizeof(char));

    NSLog(@"The size of a float is: %d bytes.",sizeof(float));

    NSLog(@"The size of a double is: %d bytes.",sizeof(double));

    NSLog(@"The size of a bool is: %d bytes.",sizeof(bool));

        [pool drain];

        return 0;

    }

    2011-08-21 09:29:16.475 sizeofTest[860:903] The size of an int is: 4 bytes.

    2011-08-21 09:29:16.478 sizeofTest[860:903] The size of a short int is: 2 bytes.

    2011-08-21 09:29:16.478 sizeofTest[860:903] The size of a long int is: 8 bytes.

    2011-08-21 09:29:16.479 sizeofTest[860:903] The size of a char is: 1 bytes.

    2011-08-21 09:29:16.479 sizeofTest[860:903] The size of a float is: 4 bytes.

    2011-08-21 09:29:16.479 sizeofTest[860:903] The size of a double is: 8 bytes.

    2011-08-21 09:29:16.480 sizeofTest[860:903] The size of a bool is: 1 bytes.

    logout

    转自:http://www.cnblogs.com/getsun/archive/2011/08/21/2147618.html

    若有不对请留言指正:

    %@:             Objective-C对象,印有字符串返回descriptionWithLocale:如果于的话,或描述相反.CFTypeRef工作对象,返回的结果的CFCopyDescription功能.(这个翻译有问题建议按照自己的理解方式理解)。

    %%:             为'%'字符;

    %d,%D,%i:   为32位整型数(int);

    %u,%U:        为32位无符号整型数(unsigned int);

    %hi:   为有符号的16位整型数(short);

    %hu:  为无符号的16位整型数(unsigned shord);

    %qi:   为有符号的64位整型数(long long);

    %qu:  为无符号的64位整型数(unsigned long long);

    %x:    为32位的无符号整型数(unsigned int),打印使用数字0-9的十六进制,小写a-f;

    %X:    为32位的无符号整型数(unsigned int),打印使用数字0-9的十六进制,大写A-F;

    %qx:   为无符号64位整数(unsigned long long),打印使用数字0-9的十六进制,小写a-f;

    %qX:   为无符号64位整数(unsigned long long),打印使用数字0-9的十六进制,大写A-F;

    %o,%O:   为32位的无符号整数(unsigned int),打印八进制数;

    %f:      为64位的浮点数(double);

    %e:      为64位的浮点数(double),打印使用小写字母e,科学计数法介绍了指数的增大而减小;

    %E:      为64位的浮点数(double),打印科学符号使用一个大写E介绍指数的增大而减小;

    %g:      为64位的浮点数(double),用%e的方式打印指数,如果指数小于4或者大于等于精度,那么%f的风格就会有不同体现;

    %G:      为64位的浮点数(double),用%E的方式打印指数,如果指数小于4或者大于等于精度,那么%f的风格就会有不同体现;

    %c:       为8位的无符号字符%c(unsigned char),通过打印NSLog()将其作为一个ASCII字符,或者,不是一个ASCII字符,八进制格式ddd或统一标准的字符编码的十六进制格式udddd,在这里d是一个数字;

    %C:       为16位Unicode字符%C(unichar),通过打印NSLog()将其作为一个ASCII字符,或者,不是一个ASCII字符,八进制格式ddd或统一标准的字符编码的十六进制格式\udddd,在这里d是一个数字;

    %s:       对于无符号字符数组空终止,%s系统中解释其输入编码,而不是别的,如utf-8;

    %S:       空终止一系列的16位Unicode字符;

    %p:       空指针(无效*),打印十六进制的数字0-9和小写a-f,前缀为0x;

    %L:       在明确规定的长度下,进行修正,下面的一批数据a,A,e,E,f,F,g,G应用于双精度长整型的参数;

    %a:       为64位的浮点数(double),按照科学计数法打印采用0x和一个十六进制数字前使用小写小数点p来介绍指数的增大而减小;

    %A:       为64位的浮点数(double),按照科学计数法打印采用0X和一个十六进制数字前使用大写字母小数点P界扫指数的增大而减小;

    %F:       为64位的浮点数(double),按照十进制表示法进行打印;

    %z:       修改说明在%z长度以下d,i,o,u,x,X适用于某一指定类型的转换或者适用于一定尺寸的整数类型的参数;

    %t:       修改说明在%t长度以下d,i,o,u,x,X适用于某一指定类型或一定尺寸的整数类型的转换的参数;

    %j:       修改说明在%j长度以下d,i,o,u,x,X适用于某一指定类型或一定尺寸的整数类型的转换的参数。

  • 相关阅读:
    springMvc
    计算机网络
    Mybatis 总结
    Spring 面试总结
    Java IO 流
    自定义类加载器
    缓存一致性协议
    dfs、bfs序
    7.26
    Trick
  • 原文地址:https://www.cnblogs.com/wi100sh/p/5535153.html
Copyright © 2020-2023  润新知