從零開始學習Object-C---第四天

來源:互聯網
上載者:User

標籤:style   blog   io   color   ar   使用   sp   資料   div   

今天主要講解Object-C的資料類型和運算式的使用,Object-C的四種基礎資料型別 (Elementary Data Type):int, float, double, char

1.int類型

  Object-C中存在兩種特殊的格式:

    1.如果整形值的第一位是0,則該整數是以八進位的計數法表示,如050表示十進位的40(0*64+5*8+0*1=40),在NSLog()中輸出如下:(%i以十進位的形式輸出,%o以八進位輸出但是不輸出前置0,%#o以八進位的形式輸出包含前置0)

#import <Foundation/Foundation.h>int main(int argc, const char * argv[]) {    @autoreleasepool {        int a = 050;        NSLog(@"%i", a);        NSLog(@"%o", a);        NSLog(@"%#o", a);    }    return 0;}輸出結果:2014-10-30 01:27:37.752 Demo2[685:29598] 402014-10-30 01:27:37.753 Demo2[685:29598] 502014-10-30 01:27:37.753 Demo2[685:29598] 050Program ended with exit code: 0

    2.整形變數以0和字母x(大小寫均可),則該整數是以十六進位法表示(註:十六進位數有0-9的數字和a到f(或A到F)之間的字母組成,其中A-F代表數字10-15),如0xFFEF0D輸出如下:

#import <Foundation/Foundation.h>int main(int argc, const char * argv[]) {    @autoreleasepool {        int b = 0xFFEF0D;        NSLog(@"%i", b);        NSLog(@"%x", b);        NSLog(@"%#x", b);    }    return 0;}輸出結果:2014-10-30 01:37:35.516 Demo2[702:32548] 167728772014-10-30 01:37:35.516 Demo2[702:32548] ffef0d2014-10-30 01:37:35.516 Demo2[702:32548] 0xffef0d

 

 

  

從零開始學習Object-C---第四天

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.