Objective-c literal

Source: Internet
Author: User

#import <Foundation/Foundation.h>

int main (int argc, const char * argv[])
{
/** below is a basic type literal example */
int a = 10; 10 is an integer literal
float F = 0.5f; 0.5f is a single-precision floating-point number literal
Double d = 3.14; 3.14 is a double-precision floating-point number literal
Long L = 100000L; 100000L is a long integer literal
char c = ' C '; ' C ' is a character type literal
const char *s = "Hello"; "Hello" for a C string literal

/** below is a composite type literal example */
struct Foo {int A, b;};

(struct foo) {. A = ten,. B = 20} is a composite type literal of struct foo
struct Foo foovar = (struct foo) {. A = ten,. b = 20};

(int[]) {1, 2, 3, 4} is a composite type literal of an int[4] array
int *arr = (int[]) {1, 2, 3, 4};

@ "Hello, world" for nsstring literal of string object reference type
NSString *str = @ "Hello, world";

@10, @ (10 + 0.5) are literal literals of the NSNumber object reference type
NSNumber *intnum = @10;
NSNumber *doublenum = @ (10 + 0.5);

@[@0, @1, @2] is the literal of a Nsarray object type; @0, @1, @2 are literals of the NSNumber object type
Nsarray *array = @[@0, @1, @2];
}

Objective-c literal

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

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.