Learning Object-C from scratch --- the next day

Source: Internet
Author: User

Start learning with a piece of code

////  main.m//  Demo1////  Created by lee on 14/10/27.//  Copyright (c) 2014年 lee. All rights reserved.//#import <Foundation/Foundation.h>int main(int argc, const char * argv[]) {    @autoreleasepool {        int quotient, numertor, denominator;        numertor = 10;        denominator = 2;        quotient = numertor/denominator;        NSLog(@"The fraction is %i/%i \nthe quotient is %i", numertor, denominator, quotient);    }    return 0;}

1. Int quotient, numertor, denominator;

Defines Integer Variables. Common Data Types in object-C are as follows:

1.1 integer int integertype = 1;

1.2 float floattype = 3.14;

1.3Double Floating PointDouble doubletype = 3.1415;

1.4 short integer short int partition type = 50;

1.5 long integerLong long int longlongtype = 123456789l;

2.Quotient = numertor/denominator;

division of variables (> numertor/denominator) and then assign the obtained value to the supplier ( quotient)

3.Nslog (@ "the fraction is % I/% I \ nthe quotient is % I", numertor, denominator, quotient );

The usage of % I in nslog is the same as that in C language, that is, as long as the % I character is found in the nslog routine, it will be automatically replaced with the corresponding variable in the routine. \ N is a line break.

The program running result is as follows:

2014-10-27 21:30:48.556 Demo1[1521:67965] The fraction is 10/2 the quotient is 5Program ended with exit code: 0

 

 

Learning Object-C from scratch --- the next day

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.