What is a diference between ((int) a) and (int(a))?

文章推薦指數: 80 %
投票人數:10人

c++ - int a = 0 and int a(0) differences - Stack Overflow Resultsfromthe2022DeveloperSurveyarenowavailable Home Public Questions Tags Users Companies Collectives ExploreCollectives Teams StackOverflowforTeams –Startcollaboratingandsharingorganizationalknowledge. CreateafreeTeam WhyTeams? Teams CreatefreeTeam Collectives™onStackOverflow Findcentralized,trustedcontentandcollaboratearoundthetechnologiesyouusemost. Learnmore Teams Q&Aforwork Connectandshareknowledgewithinasinglelocationthatisstructuredandeasytosearch. Learnmore Whatisadiferencebetween((int)a)and(int(a))? AskQuestion Asked 2years,5monthsago Modified 3monthsago Viewed 1ktimes 7 1 Whatisadifferencebetween((int)a)and(int(a))? Isthesecondexpressionvalidinpure"С"(not"C"under"C++")? c++ctype-conversion Share Improvethisquestion Follow editedMar7at22:01 NoSkill askedJan19,2020at9:44 NoSkillNoSkill 57633silverbadges1313bronzebadges 12 Seehere:en.cppreference.com/w/cpp/language/explicit_cast – BasinhetVeld Jan19,2020at9:48 Related:stackoverflow.com/questions/5048921/… – Evg Jan19,2020at9:49 2 Agoodstartwhencheckingifsomethingisvalidin"pureC"istocompilewith-std=c11-pedantic-errors(oryourcompiler'sequivalent).Itwillgiveyouacorrectanswer99%ofthetime. – StoryTeller-UnslanderMonica Jan19,2020at9:50 4 @Evg-Notoffthetopofmyhead.Butcompilersdostillhaveconformancebugsattimes,hencemy1%errormargin. – StoryTeller-UnslanderMonica Jan19,2020at9:52 1 by"pureC"youmean"C"? – M.M Jan19,2020at10:15  |  Show7morecomments 2Answers 2 Sortedby: Resettodefault Highestscore(default) Trending(recentvotescountmore) Datemodified(newestfirst) Datecreated(oldestfirst) 7 There'snodifferencebetweentheminC++.However,Csupportsonlythefirstcastoperation. Seethisexamplefromtutorial: doublex=10.3; inty; y=(int)x;//c-likecastnotation y=int(x);//functionalnotation Share Improvethisanswer Follow editedJan19,2020at10:13 alk 68.4k1010goldbadges9393silverbadges238238bronzebadges answeredJan19,2020at9:48 MohammedDeifallahMohammedDeifallah 1,27511goldbadge1010silverbadges2222bronzebadges Addacomment  |  3 (type_name)identifier(ormorespecifically(type_name)cast_expression(6.5.4))isaC-stylecast.(int(a))issyntacticallyinvalidinCunlessaisatype.Thenitcouldbepartofacasttoafunctiontakingtypeaandreturningint,whichwouldbeasyntacticallyvalidbutsemanticallyinvalidcast,souselesstoo.int(a);inCwouldbeadeclarationequivalenttointa;. C++doessupporttheint(a)syntaxforcasts(thetypenamemustbeasingleword;itdoesn'tworkwithe.g.,unsignedlong(a))onthegroundsthatint(thetypename)thenbecomeskindoflikeatypewithaparametrizedconstructor(althougheventhisisinC++groupedtogetherwithC-stylecastsasakindofadeprecatedwayofcasting,andthemorefine-grained/visiblestatic_cast/reinterpret_cast/const_castcastsarepreferred). TheC++syntaxthenappearstobequiteinterestingbecausethisworks(C++): typedefinttype_name; type_name(a);//adeclaration a=0; printf("%d\n",type_name(a));//type_name(a)isacastexprhere Share Improvethisanswer Follow editedJan19,2020at16:08 answeredJan19,2020at10:23 PSkocikPSkocik 55.2k66goldbadges8888silverbadges132132bronzebadges 2 2 wouldn'tint(a)beaananonymousintobjectwithaasparameterfortheconstructor,exactlythesamewaystring("abc")isananonymousstringconstructedwithchar*"abc"argument)? – Christophe Jan19,2020at15:24 @ChristopheYes,thatdoesmakesabitmoresenseoverall. – PSkocik Jan19,2020at16:09 Addacomment  |  YourAnswer ThanksforcontributingananswertoStackOverflow!Pleasebesuretoanswerthequestion.Providedetailsandshareyourresearch!Butavoid…Askingforhelp,clarification,orrespondingtootheranswers.Makingstatementsbasedonopinion;backthemupwithreferencesorpersonalexperience.Tolearnmore,seeourtipsonwritinggreatanswers. Draftsaved Draftdiscarded Signuporlogin SignupusingGoogle SignupusingFacebook SignupusingEmailandPassword Submit Postasaguest Name Email Required,butnevershown PostYourAnswer Discard Byclicking“PostYourAnswer”,youagreetoourtermsofservice,privacypolicyandcookiepolicy Nottheansweryou'relookingfor?Browseotherquestionstaggedc++ctype-conversionoraskyourownquestion. TheOverflowBlog Askedandanswered:theresultsforthe2022Developersurveyarehere! LivingontheEdgewithNetlify(Ep.456) FeaturedonMeta Testingnewtrafficmanagementtool Upcomingcleanupofduplicatevotes AskWizardTestResultsandNextSteps Trending:Anewanswersortingoption Updatedbuttonstylingforvotearrows:currentlyinA/Btesting Linked 36 C++castsyntaxstyles 12 DifferentmeaningsofparenthesesinC++? Related 2855 Whatisthedifferencebetween#includeand#include"filename"? 1075 Whatisthedifferencebetween++iandi++? 3712 WhatarethedifferencesbetweenapointervariableandareferencevariableinC++? 2615 HowdoIparseastringtoafloatorint? 4234 TheDefinitiveC++BookGuideandList 1658 Whatisthedifferencebetweenconstint*,constint*const,andintconst*? 9766 Whatisthe"-->"operatorinC/C++? 3217 ImproveINSERT-per-secondperformanceofSQLite 3373 HowdoIconvertaStringtoanintinJava? 26462 Whyisprocessingasortedarrayfasterthanprocessinganunsortedarray? HotNetworkQuestions HowcanIrecovermylosttimeinmycareer? HotWaterHeaterReliefValveLeakage SeparationoftheChurchandStateinHinduism EnumeratespecificequationswithRomannumeralswithstars Dosymmetricalairfoilsgenerateinduceddrag? IterativeSmallestComplement Amaneatsaghost TCP-WhydoRSTpacketsnotrequireacknowledgements(andFINpacketsdo)? JPLHorizons-"highlyaccuratemeasurementsofplanetarypositions"-howdotheydoit? RecordsgreaterthanepochtimestampusingonlyLIKEoperator Whyarejudicialcircuitssonamed? Doesthiscountasdeniedentry? WillRoadstereverencounterMars? Children’sbookwithamousecalledNils Is"¿Quédicessiterompolacara?"agoodtranslationof"what'dyousayaboutmebreakingyourface"? Isthereageneralwaytoparametrize2-qubitunitaries? TheUnaverageables Iboughtmyfirstroadbike,andithurtsmybackandhands Hiomneslingua:Whylinguaisputinsingular? HowdoIsetvaluenodeto#frameusingpython Docountries(withruleoflaw)existwhereacourtcanrequirethelegislativetovoteonalawinordertoclearambiguities? IsDatafromStarTrekabletoswim? JustificationforaMagicschoolbeingdangerous Whatdoes"CATsthreeandfour"mean? morehotquestions Questionfeed SubscribetoRSS Questionfeed TosubscribetothisRSSfeed,copyandpastethisURLintoyourRSSreader. default Yourprivacy Byclicking“Acceptallcookies”,youagreeStackExchangecanstorecookiesonyourdeviceanddiscloseinformationinaccordancewithourCookiePolicy. Acceptallcookies Customizesettings  



請為這篇文章評分?