Basic grammatical comparison of several common languages: digital processing

Source: Internet
Author: User

C + +: In the case of memory management, the overall feeling is very cool, and because it is a UNIX self-brought compiler. Very cool. The only point is that an enumeration value in an enumeration type is like a global variable name. The enumeration values are named very long. The syntax is basically not too many pauses, and the syntax involved in this example is much like the C#,java.

#include <iostream>using namespacestd;enumenum_op{Enum_op_add, Enum_op_minus, Enum_op_time, enum_op_divide};intNumbercaculate (intAintb,enum_op op) {    intret=0; Switch(OP) { Caseenum_op_add: {ret=a+b;  Break; }         CaseEnum_op_minus: {ret=a-b;  Break; }         Caseenum_op_time: {ret=a*b;  Break; }         Caseenum_op_divide: {ret=a/b; }    }    returnret;} Template<typename t>t Numbercaculatefull (t a,t b,enum_op op) {t ret=0; Switch(OP) { Caseenum_op_add: {ret=a+b;  Break; }         CaseEnum_op_minus: {ret=a-b;  Break; }         Caseenum_op_time: {ret=a*b;  Break; }         Caseenum_op_divide: {ret=a/C; }    }    returnret;}intMain () {cout<<"Hello,world"<<Endl; cout<<numbercaculate (1,3, Enum_op_minus) <<Endl; cout<<NumberCaculateFull<float> (1.2,3.3, Enum_op_time) <<Endl;}

Object-c: Because there is Xcode, the second-largest editor of the Earth (vs first), writing code is still cool. Unlike C + +, where the enum ENUM_OP op is defined for the parameters in the enumeration, it is important that generics are not fully supported. This is a gap.

////main.m//Hiworld////Created by Linson on 2018/8/19.//Copyright 2018 Linson. All rights reserved.//#import<Foundation/Foundation.h>enumenum_op{Enum_op_add, Enum_op_minus, Enum_op_time, enum_op_divide};intNumbercaculate (intAintBenumenum_op op);intMainintargcConst Char*argv[]) {@autoreleasepool {NSLog (@"Hello, world!."); intA=2; intb=4; NSLog (@"%i", Numbercaculate (A, B, Enum_op_add)); NSLog (@"%i", Numbercaculate (A, B, Enum_op_minus)); }    return 0;}intNumbercaculate (intAintBenumenum_op op) {    intret=0; Switch(OP) { Caseenum_op_add: {ret=a+b;  Break; }         CaseEnum_op_minus: {ret=a-C;  Break; }         Caseenum_op_time: {ret=a*b;  Break; }         Caseenum_op_divide: {ret=a/b; }                }    returnret;}

Basic grammatical comparison of several common languages: digital processing

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.