Difference between const char *p, char * const p and const ...
文章推薦指數: 80 %
1. const char *ptr : This is a pointer to a constant character. You cannot change the value pointed by ptr, but you can change the pointer ...
Skiptocontent
CoursesForWorkingProfessionalsLIVEDSALiveClassesSystemDesignJavaBackendDevelopmentFullStackLIVEExploreMoreSelf-PacedDSA-SelfPacedSDETheoryMust-DoCodingQuestionsExploreMoreForStudentsLIVECompetitiveProgrammingDataStructureswithC++DataScienceExploreMoreSelf-PacedDSA-SelfPacedCIPJAVA/Python/C++ExploreMoreSchoolCoursesSchoolGuidePythonProgrammingLearnToMakeAppsExploremoreAllCoursesTutorialsAlgorithmsAnalysisofAlgorithmsAsymptoticAnalysisWorst,AverageandBestCasesAsymptoticNotationsLittleoandlittleomeganotationsLowerandUpperBoundTheoryAnalysisofLoopsSolvingRecurrencesAmortizedAnalysisWhatdoes'SpaceComplexity'mean?Pseudo-polynomialAlgorithmsPolynomialTimeApproximationSchemeATimeComplexityQuestionSearchingAlgorithmsSortingAlgorithmsGraphAlgorithmsPatternSearchingGeometricAlgorithmsMathematicalBitwiseAlgorithmsRandomizedAlgorithmsGreedyAlgorithmsDynamicProgrammingDivideandConquerBacktrackingBranchandBoundAllAlgorithmsDataStructuresArraysLinkedListStackQueueBinaryTreeBinarySearchTreeHeapHashingGraphAdvancedDataStructureMatrixStringsAllDataStructuresInterviewCornerCompanyPreparationTopTopicsPracticeCompanyQuestionsInterviewExperiencesExperiencedInterviewsInternshipInterviewsCompetititveProgrammingDesignPatternsSystemDesignTutorialMultipleChoiceQuizzesLanguagesCC++JavaPythonC#JavaScriptjQuerySQLPHPScalaPerlGoLanguageHTMLCSSKotlinML&DataScienceMachineLearningDataScienceCSSubjectsMathematicsOperatingSystemDBMSComputerNetworksComputerOrganizationandArchitectureTheoryofComputationCompilerDesignDigitalLogicSoftwareEngineeringGATEGATEComputerScienceNotesLastMinuteNotesGATECSSolvedPapersGATECSOriginalPapersandOfficialKeysGATE2021DatesGATECS2021SyllabusImportantTopicsforGATECSWebTechnologiesHTMLCSSJavaScriptAngularJSReactJSNodeJSBootstrapjQueryPHPSoftwareDesignsSoftwareDesignPatternsSystemDesignTutorialSchoolLearningSchoolProgrammingMathematicsNumberSystemAlgebraTrigonometryStatisticsProbabilityGeometryMensurationCalculusMathsNotes(Class8-12)Class8NotesClass9NotesClass10NotesClass11NotesClass12NotesNCERTSolutionsClass8MathsSolutionClass9MathsSolutionClass10MathsSolutionClass11MathsSolutionClass12MathsSolutionRDSharmaSolutionsClass8MathsSolutionClass9MathsSolutionClass10MathsSolutionClass11MathsSolutionClass12MathsSolutionPhysicsNotes(Class8-11)Class8NotesClass9NotesClass10NotesClass11NotesChemistryNotesClass8NotesClass9NotesClass10NotesCSExams/PSUsISROISROCSOriginalPapersandOfficialKeysISROCSSolvedPapersISROCSSyllabusforScientist/EngineerExamUGCNETUGCNETCSNotesPaperIIUGCNETCSNotesPaperIIIUGCNETCSSolvedPapersStudentCampusAmbassadorProgramSchoolAmbassadorProgramProjectGeekoftheMonthCampusGeekoftheMonthPlacementCourseCompetititveProgrammingTestimonialsStudentChapterGeekontheTopInternshipCareersJobsApplyforJobsPostaJobHirewithUsKnowaboutJobathonJobathonPracticeAllDSAProblemsProblemoftheDayInterviewSeries:WeeklyContestsBi-WizardCoding:SchoolContestsContestsandEventsPracticeSDESheetCuratedDSAListsTop50ArrayProblemsTop50StringProblemsTop50TreeProblemsTop50GraphProblemsTop50DPProblems
ComewritearticlesforusandgetfeaturedLearnandcodewiththebestindustryexpertsGetaccesstoad-freecontent,doubtassistanceandmore!ComeandfindyourdreamjobwithusGeeksDigestQuizzesGeeksCampusGblogArticlesIDECampusMantriHomeSavedVideosCoursesGBlogPuzzlesWhat'sNew?
ChangeLanguage
DataStructuresAlgorithmsInterviewPreparationTopic-wisePracticeC++JavaPythonCompetitiveProgrammingMachineLearningHTMLSDESheetPuzzlesGFGSchoolProjects
RelatedArticles
▲RelatedArticlesDifferencebetweenconstchar*p,char*constpandconstchar*constpPointertoanArray|ArrayPointerDifferencebetweenpointertoanarrayandarrayofpointersStorageforStringsinCC++stringclassanditsapplicationsPointersinCandC++|Set1(Introduction,ArithmeticandArray)ReferencesinC++ObjectOrientedProgramminginC++auto_ptr,unique_ptr,shared_ptr,weak_ptrPointersinCandC++PointersinC/C++withExamplesC++ClassesandObjectsAccessModifiersinC++InheritanceinC++VirtualFunctionsandRuntimePolymorphisminC++VirtualFunctioninC++PolymorphisminC++EncapsulationinC++AbstractioninC++StructurevsclassinC++CanaC++classhaveanobjectofselftype?WhyistheSizeofanEmptyClassNotZeroinC++?StaticdatamembersinC++SomeinterestingfactsaboutstaticmemberfunctionsinC++FriendclassandfunctioninC++ArraysinC/C++DynamicMemoryAllocationinCusingmalloc(),calloc(),free()andrealloc()std::sort()inC++STLBitwiseOperatorsinC/C++CoreDump(Segmentationfault)inC/C++Differencebetweenconstchar*p,char*constpandconstchar*constpPointertoanArray|ArrayPointerDifferencebetweenpointertoanarrayandarrayofpointersStorageforStringsinCC++stringclassanditsapplicationsPointersinCandC++|Set1(Introduction,ArithmeticandArray)ReferencesinC++ObjectOrientedProgramminginC++auto_ptr,unique_ptr,shared_ptr,weak_ptrPointersinCandC++PointersinC/C++withExamplesC++ClassesandObjectsAccessModifiersinC++InheritanceinC++VirtualFunctionsandRuntimePolymorphisminC++VirtualFunctioninC++PolymorphisminC++EncapsulationinC++AbstractioninC++StructurevsclassinC++CanaC++classhaveanobjectofselftype?WhyistheSizeofanEmptyClassNotZeroinC++?StaticdatamembersinC++SomeinterestingfactsaboutstaticmemberfunctionsinC++FriendclassandfunctioninC++ArraysinC/C++DynamicMemoryAllocationinCusingmalloc(),calloc(),free()andrealloc()std::sort()inC++STLBitwiseOperatorsinC/C++CoreDump(Segmentationfault)inC/C++Differencebetweenconstchar*p,char*constpandconstchar*constpViewDiscussion
ImproveArticle
SaveArticle
LikeArticle
DifficultyLevel:
EasyLastUpdated:
11Sep,2021Prerequisite:Pointers Thereisalotofconfusionwhenchar,const,*,pareallusedindifferentpermutationsandmeaningschangeaccordingtowhichisplacedwhere.Followingarticlefocusondifferentiationandusageofallofthese. Thequalifierconstcanbeappliedtothedeclarationofanyvariabletospecifythatitsvaluewillnotbechanged.constkeywordappliestowhateverisimmediatelytoitsleft.Ifthereisnothingtoitsleft,itappliestowhateverisimmediatelytoitsright. 1.constchar*ptr:Thisisapointertoaconstantcharacter.Youcannotchangethevaluepointedbyptr,butyoucanchangethepointeritself.“constchar*”isa(non-const)pointertoaconstchar.C//Cprogramtoillustrate//charconst*p#include
延伸文章資訊
- 1Converting const char * to char * [SOLVED] - DaniWeb
>Is there a way to convert from const char * >to char * without casting away the const? Short ans...
- 2const char - C++ Forum
- 3How to convert const char* to char* in C? - Stack Overflow
First of all you should do such things only if it is really necessary - e.g. to use some old-styl...
- 4const char*, char const*, char*const 的区别 - 菜鸟教程
Bjarne在他的The C++ Programming Language里面给出过一个助记的方法:把一个声明从右向左读。 char * const cp; ( * 读成pointer to )...
- 5string、const char*、 char* 、char[]相互转换(全) - CSDN博客
string、const char*、 char* 、char[]四者类型经常会需要转化。 一:转化总结形式如下:. 使用时,要对源格式和目标格式进行初始化。