When to use const char * and when to use const char []

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

If you do not need to modify the data, using const char text[] reduces the number of relocations in the object file, and requires fewer machine ... 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 Whentouseconstchar*andwhentouseconstchar[] AskQuestion Asked 10years,8monthsago Modified 4monthsago Viewed 123ktimes 68 32 Iknowtheyaredifferent,IknowhowtheyaredifferentandIreadallquestionsIcouldfindregardingchar*vschar[] Butallthoseanswersnevertellwhentheyshouldbeused. Somyquestionis: Whendoyouuse constchar*text="text"; andwhendoyouuse constchartext[]="text"; Isthereanyguidelineorrule? Asanexample,whichoneisbetter: voidwithPointer() { constchar*sz="hello"; std::cout<and#include"filename"? 2971 Howdoyouset,clear,andtoggleasinglebit? 3712 WhatarethedifferencesbetweenapointervariableandareferencevariableinC++? 2059 WhatisasmartpointerandwhenshouldIuseone? 2889 Whenshouldstatic_cast,dynamic_cast,const_castandreinterpret_castbeused? 1028 Howtoconvertastd::stringtoconstchar*orchar* 4234 TheDefinitiveC++BookGuideandList 1756 Whentousevirtualdestructors? 1658 Whatisthedifferencebetweenconstint*,constint*const,andintconst*? 3217 ImproveINSERT-per-secondperformanceofSQLite HotNetworkQuestions Upperboundforrandomcorrelation Findingthelinenumberoffirstoccurrenceofatextinbashscript Isitcommontoattendtoconferenceofpastpostdocduringanewpostdoc? Whatisthemeaningof"payinginbuttons"? Isthisconceptforverylowenergyspacetravelplausible? Whyarejudicialcircuitssonamed? Whydidn’tthe1980smicrosuseMC68010? Whatdoyoucallthepointypartsofatextbubblethat'snotthetail? HowcanIaddalayerofmeaningtoanevilcampaign? Formallanguagerewriterules:strangenotation SolvingaSimple'SumandProduct'Problem Is"¿Quédicessiterompolacara?"agoodtranslationof"what'dyousayaboutmebreakingyourface"? 28yofriendlookingtoattenedundergraddegreewithouttransferringanycredits IstwistingasingleendedsignalwithitsownGNDreallyuseful? Can`a?bc`beshortenedinJavascript? RecordsgreaterthanepochtimestampusingonlyLIKEoperator 1921CensusandnotingnamedifferentinAncestry HowtomakeQuantityrememberinterpretation? WhyismydatanotnormallydistributedwhileIhaveanalmostperfectQQplotandhistogram? ShortofattackingaNATOcountry,isthereanyotherthingRussiacandototriggerdirectAmericanmilitaryconfrontation? Isitpracticaltopreventa51%-attackbyhavingasecondminingalgorithm? Doesmycathatemenow Whydoesafemale-femalecouplerbreaktheUSB-Cstandard? Palindromeanimationpausingatbeginningandend morehotquestions Questionfeed SubscribetoRSS Questionfeed TosubscribetothisRSSfeed,copyandpastethisURLintoyourRSSreader. default Yourprivacy Byclicking“Acceptallcookies”,youagreeStackExchangecanstorecookiesonyourdeviceanddiscloseinformationinaccordancewithourCookiePolicy. Acceptallcookies Customizesettings  



請為這篇文章評分?