Callbacks in C - GeeksforGeeks

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

A callback is any executable code that is passed as an argument to other code, which is expected to call back (execute) the argument at a ... 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 ▲RelatedArticlesCallbacksinCNestedfunctionsinCParameterPassingTechniquesinC/C++C++ProgrammingandSTLFactssqrt,sqrtlandsqrtfinC++PowerFunctioninC/C++tolower()functioninCMeasureexecutiontimewithhighprecisioninC/C++MeasureexecutiontimeofafunctioninC++HowtomeasuretimetakenbyafunctioninC?time()functioninCProgramtoreverseastring(IterativeandRecursive)PrintreverseofastringusingrecursionWriteaprogramtoprintallpermutationsofagivenstringPrintalldistinctpermutationsofagivenstringwithduplicatesPermutationsofagivenstringusingSTLAllpermutationsofanarrayusingSTLinC++std::next_permutationandprev_permutationinC++LexicographicallyNextPermutationinC++HowtoprintsizeofarrayparameterinC++?HowtosplitastringinC/C++,PythonandJava?boost::splitinC++libraryTokenizingastringinC++getline()FunctionandCharacterArrayinC++getline(string)inC++ArraysinC/C++DynamicMemoryAllocationinCusingmalloc(),calloc(),free()andrealloc()std::sort()inC++STLBitwiseOperatorsinC/C++CoreDump(Segmentationfault)inC/C++CallbacksinCNestedfunctionsinCParameterPassingTechniquesinC/C++C++ProgrammingandSTLFactssqrt,sqrtlandsqrtfinC++PowerFunctioninC/C++tolower()functioninCMeasureexecutiontimewithhighprecisioninC/C++MeasureexecutiontimeofafunctioninC++HowtomeasuretimetakenbyafunctioninC?time()functioninCProgramtoreverseastring(IterativeandRecursive)PrintreverseofastringusingrecursionWriteaprogramtoprintallpermutationsofagivenstringPrintalldistinctpermutationsofagivenstringwithduplicatesPermutationsofagivenstringusingSTLAllpermutationsofanarrayusingSTLinC++std::next_permutationandprev_permutationinC++LexicographicallyNextPermutationinC++HowtoprintsizeofarrayparameterinC++?HowtosplitastringinC/C++,PythonandJava?boost::splitinC++libraryTokenizingastringinC++getline()FunctionandCharacterArrayinC++getline(string)inC++ArraysinC/C++DynamicMemoryAllocationinCusingmalloc(),calloc(),free()andrealloc()std::sort()inC++STLBitwiseOperatorsinC/C++CoreDump(Segmentationfault)inC/C++CallbacksinCViewDiscussion ImproveArticle SaveArticle LikeArticle DifficultyLevel: MediumLastUpdated: 05Mar,2019Acallbackisanyexecutablecodethatispassedasanargumenttoothercode,whichisexpectedtocallback(execute)theargumentatagiventime[Source:Wiki].Insimplelanguage,Ifareferenceofafunctionispassedtoanotherfunctionasanargumenttocallit,thenitwillbecalledasaCallbackfunction.InC,acallbackfunctionisafunctionthatiscalledthroughafunctionpointer.BelowisasimpleexampleinCtoillustratetheabovedefinitiontomakeitmoreclear://AsimpleCprogramtodemonstratecallback#include  voidA(){    printf("IamfunctionA\n");}  //callbackfunctionvoidB(void(*ptr)()){    (*ptr)();//callbacktoA}  intmain(){    void(*ptr)()=&A;          //callingfunctionBandpassing    //addressofthefunctionAasargument    B(ptr);     return0;} IamfunctionA InC++STL,functorsarealsousedforthispurpose.ThisarticleiscontributedbyRanjuKumari.IfyoulikeGeeksforGeeksandwouldliketocontribute,youcanalsowriteanarticleusingcontribute.geeksforgeeks.orgormailyourarticletocontribute@geeksforgeeks.org.SeeyourarticleappearingontheGeeksforGeeksmainpageandhelpotherGeeks.Pleasewritecommentsifyoufindanythingincorrect,oryouwanttosharemoreinformationaboutthetopicdiscussedabove.MyPersonalNotes arrow_drop_upSave LikeNext NestedfunctionsinCRecommendedArticlesPage:16,Jun2216,Jun2216,Jun2214,Jun2209,Jun2203,Jun2202,Jun2201,Jun2201,Jun2201,Jun2201,Jun2224,Apr22ArticleContributedBy:GeeksforGeeksVotefordifficultyCurrentdifficulty: MediumEasy Normal Medium Hard ExpertImprovedBy:SubhajitMandalArticleTags:CPP-FunctionsCLanguageReportIssueWritingcodeincomment? Pleaseuseide.geeksforgeeks.org, generatelinkandsharethelinkhere. LoadCommentsWhat'sNewViewDetailsViewDetailsViewDetailsMostpopularinCLanguageSubstringinC++MultidimensionalArraysinC/C++LeftShiftandRightShiftOperatorsinC/C++std::stringclassinC++DifferentMethodstoReverseaStringinC++MorerelatedarticlesinCLanguagerand()andsrand()inC/C++FunctionPointerinCEnumeration(orenum)inCCommandlineargumentsinC/C++StructuresinCImproveyourCodingSkillswithPracticeTryIt! Weusecookiestoensureyouhavethebestbrowsingexperienceonourwebsite.Byusingoursite,you acknowledgethatyouhavereadandunderstoodour CookiePolicy& PrivacyPolicy GotIt! StartYourCodingJourneyNow!Login Register



請為這篇文章評分?