Optoelectronic devices: Introduction

nptelhrd
21 Sept 201450:05

Summary

TLDRThe script discusses the concept and importance of functions in programming. It explains that functions are distinct parts of a program, emphasizing their independence from other functions. The main function, 'main', is highlighted as the starting point for program execution, with duties potentially delegated to other functions. Parameters, return types, and the sequence of operations within functions are covered, including the use of loops and conditionals to control flow. The script uses the 'power' function as an example to illustrate function calls, execution, and the significance of argument order. It also touches on the function prototype's role in defining function structure for the compiler, and the practical application of functions like 'printf' and 'scanf'.

Takeaways

  • 📚 The script discusses the concept and importance of functions in programming, emphasizing their role as fundamental building blocks in a program.
  • 🔍 It clarifies that a function should be independent and not part of another function, highlighting the uniqueness of each function within a program.
  • 👀 The video introduces the 'main' function as the starting point of any C program, which is essential for understanding program execution flow.
  • 🔑 The script explains the function template, including function name, argument declarations, return type, and the body of the function where local declarations can be made.
  • 📐 It demonstrates the use of functions with parameters, such as 'power' function, to perform calculations and return results, showcasing how functions can be called with arguments.
  • 🔄 The concept of control flow within a program is explored, showing how execution moves from the 'main' function to other functions and back, including the use of loops and conditionals.
  • 📝 The script mentions the importance of understanding the order of arguments passed to functions and the potential confusion that can arise from incorrect order, as illustrated with the 'power' function.
  • 🛠️ The role of function prototypes in a program is highlighted, explaining how they provide a blueprint for the function's implementation, including the number and types of parameters and the return type.
  • 🔍 The necessity for compilers to check function prototypes for consistency with the actual function implementation is discussed, underlining the importance of correct function declaration.
  • 📈 An example of using the 'power' function within a loop is given, illustrating how functions can be integrated into larger program structures and control flows.
  • 🖥️ The transcript concludes with a practical example involving loops and function calls, demonstrating the application of concepts discussed throughout the script in a programming context.

Q & A

  • What is the basic concept of a function in programming?

    -A function is essentially a block of code designed to perform a specific task within a program. It is a fundamental part of programming that helps in organizing and reusing code effectively.

  • Why is it important for a function to be independent of other functions?

    -A function should be independent to ensure modularity and reusability. This means it should not rely on or interfere with other functions' internal workings, promoting cleaner and more maintainable code.

  • What is the purpose of the 'main' function in a program?

    -The 'main' function serves as the entry point of a program. Execution of the program begins with the 'main' function, which can then call other functions as needed.

  • How does the delegation of duties within a program work?

    -Delegation of duties involves the 'main' function passing control to other functions when necessary. This allows for specific tasks to be handled by specialized functions, which then return control and results back to the 'main' function or other parts of the program.

  • What is the significance of parameters in a function call?

    -Parameters are used to pass values into a function, allowing the function to operate on different data each time it is called. They are essential for making functions versatile and dynamic.

  • Can you explain the concept of 'return' in functions?

    -The 'return' statement is used in functions to send values back to the caller. It can be used to output the result of a computation or pass data back to the part of the program that invoked the function.

  • What is the role of the 'printf' function in programming?

    -The 'printf' function is used for formatted output. It allows programmers to print variables and other data to the console or screen in a specified format.

  • How does the order of arguments in a function call affect the outcome?

    -The order of arguments is crucial as it must match the order of parameters defined in the function. Incorrect ordering can lead to incorrect operations and results within the function.

  • What is a function prototype and why is it important?

    -A function prototype declares the function's name, return type, and the types and order of its parameters. It is important because it informs the compiler about the function's signature, allowing for type checking and ensuring the correct use of the function.

  • Can a function call within a program affect the control flow?

    -Yes, a function call can alter the control flow by transferring execution to the called function. Upon completion, control is returned to the point from which the function was called, potentially altering the sequence of execution.

  • What is the significance of the 'return' type in a function?

    -The 'return' type specifies the kind of value a function will return. It is important for the calling code to know what type of data to expect from the function, enabling proper handling of the returned value.

Outlines

00:00

📚 Introduction to Functions

The script begins with an introduction to the concept of functions in programming. It explains that functions are fundamental components of a program and emphasizes the importance of understanding how they operate independently from other functions. The main function, 'main', is highlighted as the starting point of any program, and the necessity of delegating tasks within the main function to other functions is discussed. The script also touches on the idea that functions should not be part of another function, and the importance of parameter passing within functions is introduced.

05:01

🔍 Deeper Dive into Function Mechanics

This paragraph delves deeper into the mechanics of functions, discussing their purpose and how they are used within a program. It covers the function template, including the function name, argument declarations, and return type. The concept of arguments is explored, explaining their role as inputs to functions and the importance of their order and type. The paragraph also introduces the idea of return expressions and how functions can return values to the caller. The summary also touches on the notion of function prototypes and their significance in helping compilers understand function structure.

10:01

🛠 Understanding Function Prototypes and Calls

The script continues with an explanation of function prototypes, which are essential for compilers to check the correct usage of functions. It discusses how prototypes specify the number and types of parameters a function expects and its return type. The importance of function calls, or invocations, is highlighted, showing how control flow is transferred to the function and then back to the caller upon completion. The paragraph also introduces the concept of control flow within programs, starting from the main function and branching out to other functions as needed.

15:03

🔢 Exploring the Power Function and Control Flow

The script presents a specific example of a power function and explains how it is defined and used within a program. It discusses the process of calculating the power of a number and how the result is returned and printed to the screen. The paragraph also illustrates the control flow within the main function, showing how variables are declared, how function calls are made, and how the program progresses from one line to the next, including the use of loops and conditional statements.

20:07

🔄 Loops and Function Calls in Action

This paragraph discusses the use of loops in conjunction with function calls. It describes how the power function is used within a loop to perform calculations iteratively and how the results are printed to the screen using printf. The explanation includes the process of incrementing loop variables and checking conditions at the end of each loop iteration. The paragraph emphasizes the complexity of control flow when combining loops with function calls and the importance of understanding the sequence of operations.

27:12

📝 Conclusion and Final Thoughts on Functions

The final paragraph wraps up the discussion on functions by summarizing the key points covered in the script. It reiterates the importance of understanding functions, their independence, and their role in breaking down complex tasks into manageable sub-tasks. The paragraph also highlights the significance of main functions, parameter passing, and return values. It concludes with a note on the practical use of functions like printf and scanf, and hints at further exploration of these concepts in future lessons.

Mindmap

Keywords

💡Function

In the context of the video, a 'Function' is a fundamental concept in programming, representing a block of code designed to perform a specific task. It is crucial for understanding the video's theme as it explains how functions operate within a program. For example, the script mentions 'మెయిన్' (main) function, which is the entry point of a program, and 'పవర్' (power) function, which is used to calculate exponentiation.

💡Control Flow

Control Flow refers to the order in which individual statements, instructions, or function calls of an imperative program are executed. It is key to understanding the script's narrative as it describes how execution moves from the main function to other functions and back. The script illustrates this with the use of functions and loops, showing how control is passed and returned.

💡Parameters

Parameters are the variables listed in a function definition that are used to pass arguments into the function. They are essential to the video's theme as they enable functions to receive input. The script uses terms like 'ఆర్గుమెంట్స్' (arguments) to illustrate how values are passed to functions like 'పవర్' (power), affecting the function's operation.

💡Return Value

A 'Return Value' is the result that a function outputs. It is a fundamental part of the video's content as it discusses how functions like 'printf' and 'power' produce output. The script mentions 'రిటర్న్' (return) to explain how functions provide results back to the caller.

💡Prototype

A 'Prototype' in programming defines the interface for a function by specifying its name, the type and order of its parameters, and its return type. The video script touches on this concept when discussing how functions are declared and used within a program, emphasizing the importance of matching function calls with their prototypes.

💡Loop

A 'Loop' is a programming construct that allows code to be executed repeatedly based on a condition. The script discusses loops in the context of control flow, showing how they can be used to repeat function calls and other operations. The example of using a loop to print powers of numbers illustrates this concept.

💡Control Structures

Control Structures determine the order in which statements are executed in a program. The video script explains various control structures like loops and conditional statements, which are central to the theme of program execution and function interaction.

💡Arguments

Arguments are the actual values that are passed to a function when it is called. The script uses the term 'ఆర్గుమెంట్స్' to explain how data is provided to functions, affecting their behavior and the computation that takes place within them.

💡Declaration

A 'Declaration' in programming is the act of announcing a variable or function's existence and type to the compiler. The video script refers to variable and function declarations, which is essential for setting up the environment for execution.

💡Execution

Execution refers to the running of a program or part of a program. The video script discusses the execution of the main function and other functions, highlighting the process from start to finish, including the calling of functions and the use of loops.

💡printf

The 'printf' function is a standard library function in C used for formatted output to the console. The script mentions 'printf' as an example of a function that is called with parameters to print values to the screen, demonstrating its use in the context of the program's output.

Highlights

Introduction to the concept of functions in programming and their basic components.

Explanation of how functions operate independently and do not form part of another function.

Discussion on the importance of the 'main' function and its role in initiating program execution.

The necessity of understanding the sequence of function calls and control flow within a program.

Clarification on the use of parameters within functions and their impact on the program's logic.

The role of return values in functions and how they contribute to the program's output.

The significance of function prototypes in defining the structure and behavior of functions.

Explanation of how the order of arguments in function calls affects the outcome.

The importance of declaring variables within the scope of functions.

The concept of recursion and how functions can call themselves within the program.

The impact of control structures like loops and conditional statements on the flow of a program.

The use of 'printf' as a function to display output on the screen.

The practical application of functions in solving mathematical problems, such as calculating powers.

The process of function definition and invocation within the 'main' function.

The concept of passing parameters by value and how it affects the function's execution.

The importance of understanding the end of a function's execution and the return to the caller.

The explanation of how to handle multiple tasks within a program using functions.

Transcripts

play00:00

మునుపటి మాడ్యూల్‌లో, ఫంక్షన్‌ల యొక్క

play00:03

ప్రాథమిక అంశాలు మరియు ఇది ఎలా బాగుంది

play00:09

మరియు అది ఎలా చదవగలిగేలా చేస్తుంది మొదలైనవాటిని

play00:15

చూశాము.

play00:16

ఈ మాడ్యూల్‌లో, మేము ఈ ఫంక్షన్‌ల భావన

play00:21

మరియు మరిన్ని వివరాలను పరిశీలిస్తాము.

play00:25

ఫంక్షన్ అంటే ఏమిటి?

play00:28

ఫంక్షన్ తప్పనిసరిగా మీ ప్రోగ్రామ్‌లో

play00:32

ఒక భాగం.

play00:34

కాబట్టి, మీరు జాగ్రత్తగా ఉండవలసిన ఒక విషయం

play00:39

ఏమిటంటే, ఇది ఏ ఇతర ఫంక్షన్‌లో భాగం

play00:45

కాకూడదు.

play00:46

ఒక ఫంక్షన్ ఏ ఇతర ఫంక్షన్‌లో భాగం

play00:52

కాకూడదు.

play00:53

మునుపటి మాడ్యూల్‌లో మనం మెయిన్ అనే ఫంక్షన్

play00:58

ఉందని చూశాము, అది కాలర్ మరియు పవర్

play01:04

అనే ఫంక్షన్ ఉంది, అది కాళీ.

play01:09

మేము పవర్ ప్రోగ్రామ్ తీసుకొని పూర్తిగా

play01:13

కాలర్‌లో ఉంచలేము.

play01:15

మరొక ఫంక్షన్ లోపల ఒక ఫంక్షన్ పూర్తిగా

play01:21

వ్రాయబడదు.

play01:22

కాబట్టి, అలా చేయడానికి మిమ్మల్ని అనుమతించే

play01:27

కొన్ని భాషలు ఉన్నాయి. C మిమ్మల్ని దీన్ని

play01:32

అనుమతించదు, ఇది మెయిన్ ఫంక్షన్ అని

play01:35

నేను ఇంతకు ముందు పేర్కొన్నాను.

play01:38

మీకు బహుళ సబ్ టాస్క్ లు ఉన్నప్పుడు, మీరు

play01:43

ప్రారంభించాల్సిన మొదటి పని ఏమిటో

play01:46

ఎవరైనా తెలుసుకోవాలి.

play01:47

సాధారణంగా ఇది మెయిన్.

play01:50

కాబట్టి, మీరు మెయిన్‌తో ప్రారంభించండి, మెయిన్‌కి

play01:53

దశల క్రమం ఉంటుంది, మెయిన్ నుండి మీకు

play01:57

కావలసిన ఏదైనా డ్యూటీ డెలిగేషన్ కావాలంటే,

play02:01

మెయిన్ ప్రోగ్రామ్‌లో అది ఉండాలి, మెయిన్

play02:05

ఫంక్షన్‌లో డ్యూటీ డెలిగేషన్ ఉండాలి.

play02:07

మేము మెయిన్ ఫంక్షన్ నుండి పవర్ కి డ్యూటీ

play02:12

డెలిగేషన్ ని కలిగి ఉన్నాము.

play02:15

కాబట్టి, ఎగ్జిక్యూషన్ మెయిన్ ఫంక్షన్ నుండి

play02:19

ప్రారంభమవుతుంది, కంట్రోల్ ఫ్లో అక్కడ

play02:22

మొదలవుతాయి, అక్కడ నుండి కంట్రోల్ ఫ్లో

play02:25

ఒక ఫంక్షన్ లేదా మరొకదానికి తరలించవచ్చు

play02:29

మరియు వెనుకకు తిరిగి వస్తుంది.

play02:32

మీరు కాలర్ నుండి కొత్త ఫంక్షన్‌కి

play02:35

కాల్ చేసిన ప్రతిసారీ, మీరు తప్పనిసరిగా

play02:39

కంట్రోల్ ను కాళ్ళీ కి బదిలీ చేస్తున్నారు.

play02:43

కాబట్టి, ఫంక్షన్ కాల్‌తో మీరు సాధారణంగా

play02:47

కొన్ని పారామీటర్స్ లను పాస్ చేస్తారు.

play02:50

మన విషయంలో మనం బేస్ మరియు nని పాస్ చేసాము

play02:56

మరియు ఈ పారామీటర్స్ ఫంక్షన్‌లో ఉపయోగించబడతాయి.

play03:00

మీరు కొంత విలువను గణిస్తారు, విలువలు

play03:03

కాలర్‌కు తిరిగి వస్తాయి మరియు కాలర్

play03:07

దానిని వేరే గణనలో ఉపయోగించవచ్చు.

play03:10

కాలర్, ఉత్పత్తి చేయబడిన విలువను

play03:13

విస్మరించడాన్ని కూడా ఎంచుకోవచ్చు.

play03:15

నిజానికి, printf సాంకేతికంగా సరైనది, వాస్తవానికి

play03:20

తిరిగి విలువను ఉత్పత్తి చేస్తుంది.

play03:24

కేవలం, సాధారణంగా మేము printf నుండి రిటర్న్

play03:30

విలువను విస్మరించడాన్ని ఎంచుకుంటాము.

play03:32

ఇది కొంత పని చేస్తుంది, ఇది స్క్రీన్‌పై

play03:36

విషయాలను ప్రింట్ చేస్తుంది, ఇది వాస్తవానికి

play03:40

విలువను కూడా అందిస్తుంది, మేము సాధారణంగా రిటర్న్

play03:44

విలువ గురించి పట్టించుకోము.

play03:46

ఇది చాలా మంది ప్రోగ్రామర్లకు ఉపయోగపడదు.

play03:50

ఫంక్షన్ యొక్క టెంప్లేట్ ని చూద్దాం.

play03:54

మాకు ఫంక్షన్ పేరు ఉంది మరియు మా వద్ద

play03:59

అన్ని ఆర్గ్యుమెంట్ డిక్లరేషన్‌లు ఉన్నాయి

play04:01

మరియు మాకు రిటర్న్ టైపు ఉంది మరియు

play04:06

మీరు మీ ప్రోగ్రామ్‌లోనే మరిన్ని డిక్లరేషన్‌లను

play04:09

కోరుకోవచ్చు.

play04:10

మీకు స్టేట్‌మెంట్‌లలో మరిన్ని డిక్లరేషన్‌లు

play04:13

ఉన్నాయి మరియు చివరగా, మీకు రిటర్న్ ఎక్స్‌ప్రెషన్

play04:17

ఉంటుంది.

play04:18

ఫంక్షన్ పేరు, మీరు ఈ సబ్ టాస్క్ కాల్

play04:23

చేయబోయే పేరును గుర్తిస్తుంది.

play04:25

ఇది కొన్ని ఆర్గుమెంట్స్ ని కలిగి ఉండవచ్చు,

play04:30

ఆర్గుమెంట్స్ వాటి పేర్లు మరియు ఆర్గుమెంట్

play04:33

లు ఇవ్వవలసిన క్రమాన్ని కలిగి ఉంటాయి.

play04:37

ఉదాహరణకు, పవర్ ఆఫ్ బేస్ కామా n కి మీరు

play04:42

3 కామా 5ని పాస్ చేస్తే, మేము 3 పవర్ 5 చేస్తాము.

play04:48

బదులుగా, మీరు పవర్ ఆఫ్ 5 కామా 3 అని చెబితే,

play04:53

అది వాస్తవానికి 5 పవర్ 3 అని అర్ధం,

play04:58

మీకు ఫలితం 125 వస్తుంది.

play05:00

కాబట్టి, మీరు గుర్తించడంలో జాగ్రత్తగా ఉండాలి,

play05:03

ఆర్గుమెంట్స్ ఏమిటి మరియు ఆర్గుమెంట్స్

play05:06

ఏ క్రమంలో పాస్ చేయబడ్డాయి మరియు మీరు ఫంక్షన్

play05:10

లో ఉన్న వివిధ ప్రకటనలను కలిగి ఉంటారు.

play05:14

ఉదాహరణకు, మనకు int i మరియు int p అవసరమవుతాయి,

play05:18

ఇవి లూప్‌ను అమలు చేయడంలో ఉపయోగపడతాయి.

play05:22

చివరగా, మనకు రిటర్న్ ఎక్స్‌ప్రెషన్ ఉంది,

play05:26

ముందుగా pని రిటర్న్ చేయండి మరియు మా

play05:31

పవర్ ఫంక్షన్‌లో రిటర్న్ టైప్ ఉంది,

play05:34

అది ఇంటీజర్.

play05:36

మీరు గుర్తుంచుకోవాల్సిన ఒక విషయం ఏమిటంటే,

play05:40

ఒక ఫంక్షన్ యొక్క బాడీ లో, ఇది కోడ్

play05:45

యొక్క ప్రాథమిక బ్లాక్ మరియు ఫంక్షన్ యొక్క

play05:50

బాడీలో ఉంటుంది, మీరు ఇతర ఫంక్షన్

play05:54

డిక్లరేషన్‌లను కలిగి ఉండలేరు.

play05:56

కాబట్టి, మరొక ఫంక్షన్‌లో పూర్తిగా ప్రకటించబడిన

play06:00

మరియు వివరించబడిన ఇతర ఫంక్షన్‌లను

play06:03

కలిగి ఉండటానికి ఇది అనుమతించబడదు.

play06:07

ఆర్గ్యుమెంట్‌లు తప్పనిసరిగా ఇన్‌పుట్‌లను

play06:09

కనుగొన్నాయి, మీకు టైప్స్ మరియు ఆర్డర్

play06:13

రెండూ అవసరం.

play06:14

కొన్నిసార్లు, రిటర్న్ ఎక్స్‌ప్రెషన్ ఐచ్ఛికం.

play06:17

కాబట్టి, కీవర్డ్ రిటర్న్ ఎక్స్‌ప్రెషన్‌ను

play06:21

తీసుకోవచ్చు, అది ఎలాంటి ఎక్స్‌ప్రెషన్‌ను

play06:24

తీసుకోదు మరియు రిటర్న్ అని చెప్పదు లేదా

play06:28

మీకు రిటర్న్ కూడా లేకపోతే, మీ ప్రోగ్రామ్

play06:33

సబ్ టాస్క్ యొక్క చివరి ముగింపు బ్రేస్

play06:38

కు వస్తుంది మరియు స్వయంచాలకంగా, అది

play06:42

కాలర్‌కి తిరిగి వెళుతుంది.

play06:44

కాబట్టి, ఫంక్షన్‌ను ప్రారంభించడం సాధారణంగా

play06:47

ఈ ఫంక్షన్ పేరును ఉపయోగించి చేయబడుతుంది

play06:51

మరియు మీరు ఆమోదించిన అన్ని పారామీటర్

play06:55

ల సమితిని కలిగి ఉంటారు.

play06:58

ఫంక్షన్ యొక్క ప్రోటోటైప్ అని పిలవబడే దాని

play07:03

గురించి ఈ భావన ఉంది.

play07:06

మేము దీన్ని కొద్దిసేపట్లో చూస్తాము.

play07:09

నేను ఒక ప్రోగ్రామ్‌లో దాన్ని కలిగి ఉన్నాను,

play07:14

కానీ నేను ఇంతకు ముందు దాని వివరాలలోకి

play07:19

వెళ్లలేదు, కానీ ప్రోటోటైప్ అంటే

play07:22

ఏమిటో చూద్దాం.

play07:23

ప్రోటోటైప్ తప్పనిసరిగా పారామీటర్ ల సంఖ్య

play07:27

మరియు ప్రతి పారామీటర్ రకాన్ని నిర్వచిస్తుంది.

play07:31

ఇది ఫంక్షన్ యొక్క రిటర్న్ విలువను

play07:35

కూడా నిర్వచిస్తుంది.

play07:37

ప్రోటోటైప్ తప్పనిసరిగా మీకు బ్లాక్ బాక్స్

play07:40

వివరణను ఇస్తుంది.

play07:42

ప్రతి ఫంక్షన్‌కు ప్రోటోటైప్ , ఫంక్షన్

play07:45

యొక్క వాస్తవ నిర్వచనం ఉంటుంది.

play07:48

బ్లాక్ బాక్స్ వివరణ ఏమిటో ప్రోటోటైప్

play07:52

మీకు చెబుతుంది, ఇన్‌పుట్‌లు ఏమిటి

play07:55

మరియు అవుట్‌పుట్‌లు ఏమిటి మరియు కొన్నింటిలో

play07:59

మీరు ఫంక్షన్‌ను చేయడానికి ప్రోగ్రామ్‌ను

play08:02

వ్రాయవలసి ఉంటుంది మరియు అది ఫంక్షన్

play08:06

అమలు.

play08:07

ప్రోటోటైప్ అవసరమైన విషయం, కంపైలర్‌లు

play08:10

సాధారణంగా ప్రోటోటైప్ ఉందా లేదా అని తనిఖీ

play08:15

చేస్తాయి.

play08:16

మేము ప్రోటోటైప్ ఇస్తే, మీరు ఏదైనా

play08:20

మర్చిపోయినట్లయితే కంపైలర్ వాస్తవానికి

play08:22

హెచ్చరికల ద్వారా సూచిస్తుంది.

play08:24

మీరు ఒక ఫంక్షన్‌ని రిటర్న్ చేసారు మరియు

play08:29

దానికి మూడు పారామీటర్‌లు అందిస్తారు మరియు

play08:33

మీరు దానిని పిలిచిన ప్రతిచోటా, మీరు

play08:37

రెండు పారామీటర్‌లు మాత్రమే పాస్ చేస్తారు.

play08:41

కంపైలర్ దానిని గుర్తించి, ఈ ఫంక్షన్ మూడు పారామీటర్

play08:46

లను ఆశిస్తున్నట్లు మరియు మీరు కేవలం

play08:50

రెండింటిని మాత్రమే పాస్ చేసారని మీకు

play08:54

తెలియజేస్తుంది.

play08:55

ఇక్కడ ప్రోటోటైప్ పవర్, ఈ క్రింది విధంగా

play09:00

ఉంది, int power . కాబట్టి, ఈ స్థానంలో మనము

play09:03

వాస్తవానికి పారామీటర్స్ పేరు పెట్టబడలేదు,

play09:06

పవర్ రెండు పారామీటర్ లను తీసుకుంటుంది,

play09:09

కానీ పేర్లు పేర్కొనబడలేదు.

play09:10

కంపైలర్ ఈ ప్రోటోటైప్‌ను చూసినప్పుడు, పవర్

play09:13

రెండు ఇంటిజెర్ లను తీసుకునే ఒక ఫంక్షన్‌గా

play09:17

భావించబడి, మరొక ఇంటిజెర్ ని తిరిగి

play09:20

ఇస్తుంది.

play09:21

ఈ సమయంలో, కంపైలర్‌కు బేస్ మొదటి పారామీటర్

play09:24

మరియు n రెండవ పారామీటర్ లేదా n మొదటి పారామీటర్

play09:29

మరియు బేస్ రెండవ పారామీటర్ కాదా అనేది

play09:34

తెలియదు.

play09:35

నిజానికి, అది ఈ సమయంలో పట్టించుకోడు.

play09:39

అయితే, తరువాత మేము నిజానికి వేరియబుల్స్

play09:43

బేస్ మరియు n ఇక్కడ ఉంచాము మరియు తగిన

play09:49

విధంగా ప్రోగ్రామ్‌ను వ్రాస్తాము.

play09:51

సాధారణంగా, ప్రోగ్రామ్ ప్రారంభంలో ఫంక్షన్

play09:54

ప్రోటోటైప్‌లు ఇవ్వబడతాయి.

play09:56

ఇది చూద్దాం, నేను ఇంతకు ముందు కలిగి

play10:01

ఉన్న అదే కోడ్ భాగాన్ని చూపుతున్నాను.

play10:05

మనకు ఈ పవర్ ఫంక్షన్ ఉంది.

play10:09

కాబట్టి, మీరు కుడి వైపున చూసేదాన్ని

play10:13

ఫంక్షన్ డెఫినిషన్ లేదా ఫంక్షన్ వివరణ

play10:17

అని పిలుస్తారు.

play10:19

ఇక్కడ ఈ లైన్‌లో మీరు చూసేదాన్ని,

play10:23

ఎడమ వైపున ఫంక్షన్ ప్రోటోటైప్ అంటారు.

play10:27

మనకు ఫంక్షన్ ప్రోటోటైప్ మరియు ఫంక్షన్ డెఫినిషన్

play10:32

ఉన్నాయి.

play10:33

ఫంక్షన్ ప్రోటోటైప్ చాలా ఆసక్తికరంగా

play10:36

లేదు, కానీ కంపైలర్‌కు చెప్పడం అవసరం, అలాగే

play10:41

పవర్ వాస్తవానికి రెండు వేరియబుల్స్‌ను

play10:45

ఆశిస్తుంది మరియు అది ఇంటిజెర్ ని

play10:49

మాత్రమే తిరిగి ఇస్తుంది, అది అక్షరాన్ని తిరిగి

play10:54

ఇవ్వదు, ఇది ఫ్లోటింగ్ పాయింట్ విలువను

play10:58

తిరిగి ఇవ్వదు మరియు అందువలన.

play11:01

ఫంక్షన్‌ను ఉపయోగించే ఎవరికైనా వారు ఏమి

play11:05

చేస్తున్నారో తెలుసు.

play11:07

దీనిని ఫంక్షన్ ప్రోటోటైప్ అంటారు మరియు దీనిని

play11:12

ఫంక్షన్ ఇన్వొకేషన్ అంటారు.

play11:14

మనం ఫంక్షన్‌ని కాల్ చేసినప్పుడు, మేము

play11:18

ఆ ఫంక్షన్‌ ఇన్వొకేషన్ లేదా కాలింగ్ ది

play11:23

ఫంక్షన్‌ అని పిలుస్తాము.

play11:26

ఇంతకు ముందు నేను చెప్పాను, నేను కంట్రోల్

play11:31

ఫ్లో అని పిలవబడే దాన్ని తాకాలనుకుంటున్నాను.

play11:35

నేను చెప్పాను, ప్రోగ్రామ్‌ ఫ్లో అనేది మెయిన్

play11:40

ప్రోగ్రామ్‌తో మొదలవుతుంది మరియు అది ఫంక్షన్‌ని

play11:44

కాల్ చేసినప్పుడు అది అక్కడికి వెళ్తుంది

play11:48

మరియు కొనసాగుతుంది.

play11:50

నేను ఇప్పుడు కొంచెం స్పష్టంగా చెప్పాలనుకుంటున్నాను.

play11:54

కాబట్టి, ఈ ప్రోగ్రామ్ భాగాన్ని చూద్దాం

play11:58

మరియు ఈ ఫంక్షన్ ఎలా లేదా ఈ ప్రోగ్రామ్

play12:04

ఎలా అమలు చేయబడుతుందో చూద్దాం.

play12:07

నేను ఇంతకు ముందు చెప్పినట్లుగా, అన్ని

play12:11

అమలులు మెయిన్‌తో ప్రారంభమవుతాయి,

play12:13

మీరు మెయిన్‌తో ప్రారంభించండి.

play12:16

ఈ సమయంలో మీకు రెండు డిక్లరేషన్‌లు ఉన్నాయి,

play12:21

num1 మరియు num2.

play12:23

కాబట్టి, ఏదైనా వేరియబుల్స్ మాదిరిగానే, కంపైలర్

play12:27

num1 మరియు num2 కోసం మెమరీని కేటాయించింది.

play12:32

కాబట్టి, నేను ఈ పంక్తిని అమలు చేయడానికి సిద్ధంగా

play12:38

ఉన్నాను, num1 = power . ఆ సమయంలో ఏమి జరుగుతుంది,

play12:45

ఇక్కడ సాధారణంగా జరిగే తదుపరి లైన్‌కి

play12:52

వెళ్లే బదులు.

play12:55

మేము ప్రోగ్రామ్ లను చూసినప్పుడు.

play13:00

ఫర్ లూప్‌లు మరియు ఇతర విషయాల కోసం,

play13:08

స్క్రీన్‌పై మీరు చూసే ఈ కోడ్ సీక్వెన్స్

play13:16

ఎలా అంతర్గతంగా ఎలా అమలు చేయబడుతుందో

play13:23

మేము ఇంతకు ముందు చూశాము.

play13:28

కాబట్టి, మీకు లూప్‌లు లేదా బ్రాంచ్ లు

play13:36

లేకుంటే మీరు లైన్ 1 నుండి ప్రారంభించండి,

play13:44

మీరు లైన్ 2, లైన్ 3, లైన్ 4, లైన్ n వరకు

play13:56

వెళ్లి మీరు రిటర్న్ అవుతారు.

play13:59

ఒకవేళ మీకు ఇఫ్ -థెన్- ఎల్స్ బ్రాంచ్ లు

play14:05

ఉంటే, ఇఫ్ కండీషన్ నిజమైతే లేదా ఎల్స్

play14:10

కండీషన్ నిజం మరియు వాటిలో ఒకటి మాత్రమే

play14:15

పని చేస్తుంది, మా వద్ద ఫర్ లూప్ ఉంటే,

play14:21

మీకు రిపీటెడ్ బాడీ ఉంటుంది మరియు అవన్నీ

play14:26

కంట్రోల్ ఫ్లో కి ఉదాహరణలు.

play14:29

కంట్రోల్ ఫ్లో కి ఇది మరొక ఉదాహరణ.

play14:34

కాబట్టి, ఈ సమయంలో మీరు మెయిన్‌లో లైన్

play14:39

నంబర్ 2లో ఉన్నట్లయితే, కంట్రోల్ పవర్ లో

play14:44

లైన్ నంబర్ 1కి బదిలీ చేయబడుతుంది, ఆపై

play14:49

మీరు వెళ్లి వాస్తవానికి ఈ ఆపరేషన్ల క్రమాన్ని

play14:54

చేయండి.

play14:55

ఈ ఆపరేషన్ల క్రమం పూర్తయిన తర్వాత,

play14:59

మీరు ఈ లైన్‌కి తిరిగి వెళ్లండి.

play15:03

మీరు తిరిగి వచ్చినప్పుడు, ఏమి జరుగుతుంది.

play15:07

మీరు power విలువని గణించారు, దాని ఫలితంగా గణించబడిన

play15:13

సంఖ్య 243 ఉండాలి మరియు అది సంఖ్య 1కి కేటాయించబడుతుంది.

play15:20

ఇప్పుడు, మీరు మళ్లీ కాలర్‌లోకి తిరిగి

play15:25

వచ్చారు, కాలర్‌లో, మీరు డిఫాల్ట్‌గా

play15:28

తదుపరి లైన్‌కి వెళతారు.

play15:31

తదుపరి లైన్ కూడా ఫంక్షన్ ఇన్వొకేషన్

play15:36

లేదా ఫంక్షన్ కాల్, మళ్లీ కంట్రోల్ కాలీ

play15:41

కి బదిలీ చేయబడుతుంది.

play15:44

కాలీలో, ఇది ఇక్కడ కోడ్ యొక్క క్రమం

play15:50

ద్వారా వెళుతుంది, దాని చివరిలో మీరు

play15:54

కాలర్‌కి తిరిగి వస్తారు.

play15:57

ఈ సందర్భంలో, -4,3 అనేది -64 అని లెక్కించింది,

play16:04

ఆ విలువ num2కి కేటాయించబడుతుంది.

play16:08

కాబట్టి, ఇది ఈ స్థానానికి తిరిగి వస్తుంది

play16:13

మరియు మీరు ఈ రెండు సంఖ్యల ప్రింటింగ్

play16:19

చేయడానికి సిద్ధంగా ఉన్నారు.

play16:21

ఈ ప్రోగ్రామ్ కోసం కంట్రోల్ ఫ్లో, మీరు

play16:27

మెయిన్ తో ప్రారంభించండి, ఈ లైన్‌లో మీరు ఈ

play16:34

వైపు పిలుస్తారు.

play16:35

కాబట్టి, ప్రతి అసైన్‌మెంట్ ఆపరేషన్ కోసం గుర్తుంచుకోండి,

play16:41

మీరు కుడి వైపున మూల్యాంకనం చేసి,

play16:46

మీరు దానిని ఎడమ వైపుకు కేటాయించారు.

play16:50

కాబట్టి, కుడి వైపున మూల్యాంకనం ఉంది.

play16:55

power అనేది నియంత్రణను పవర్ ఫంక్షన్‌కు

play17:00

బదిలీ చేస్తుంది మరియు మీరు దశల క్రమాన్ని

play17:05

చేయండి, కంట్రోల్ ఇక్కడకు తిరిగి వస్తుంది,

play17:10

మీరు ఈ అసైన్‌మెంట్ చేయండి, నియంత్రణ

play17:15

డిఫాల్ట్‌గా తదుపరి లైన్ కి వస్తుంది.

play17:20

మళ్ళీ కుడి వైపున తదుపరి లైన్, అది

play17:25

ఒక ఫంక్షన్ కాల్ చేస్తుంది, మీరు

play17:30

దీన్ని చేయండి మీరు ఇక్కడకు తిరిగి వచ్చి,

play17:36

అసైన్‌మెంట్ చేయండి మరియు మీరు ఒక printf

play17:41

తర్వాత మరొక printfని కలిగి ఉన్నారు మరియు

play17:46

అందువలన.

play17:47

నిజానికి, సాంకేతికంగా printf అనేది మరొక ఫంక్షన్.

play17:50

కాబట్టి, మీరు ఇక్కడకు వచ్చినప్పుడు, printf

play17:54

అనేది రెండు పారామీటర్ లు, ఒక ఫార్మాట్ మరియు

play18:00

విలువను తీసుకునే ఒక ఫంక్షన్.

play18:03

ఈ రెండూ printfకి పంపబడే పారామీటర్ లు.

play18:08

నిజానికి, printf లోపల ఏమి జరుగుతుందో అది

play18:12

దాచబడినది .

play18:13

కంట్రోల్ వాస్తవానికి printfకి బదిలీ చేయబడుతుంది,

play18:15

స్క్రీన్‌పై విషయాలను ప్రింట్ చేయడానికి

play18:17

printf ఏమైనా చేస్తుంది, అది ఈ లైన్‌కి మరియు

play18:24

తదుపరి లైన్‌కు తిరిగి వస్తుంది, అది కాలర్‌కి

play18:31

వెళ్తుంది, తదుపరి లైన్‌కి, మళ్లీ ఇది

play18:37

printf ద్వారా కాల్ చేయబడినది, మీరు printf యొక్క అంతర్గత

play18:43

విషయాలకి వెళ్ళి, అది స్క్రీన్‌పై

play18:46

ఏది ప్రింట్ చేయాలో అది చేస్తుంది, తిరిగి

play18:50

ఇక్కడకు వస్తుంది మరియు అది ఇక్కడకు

play18:54

వస్తుంది మరియు రిటర్న్‌తో ఈ లైన్‌కు వస్తుంది

play18:58

మరియు మెయిన్ ఫంక్షన్‌లోని చివరి లైన్ రిటర్న్

play19:02

0, ఇది 0ని అందిస్తుంది.

play19:05

మెయిన్ అనేది ఫంక్షన్ అని మీరు గమనించినట్లయితే,

play19:09

ఇది రిటర్న్ విలువ, ఇది ఫంక్షన్ పేరు

play19:13

మరియు ఇది రిటర్న్ స్టేట్‌మెంట్ మరియు

play19:17

మెయిన్ అనేది ఏ పారామీటర్ లను తీసుకోని ఫంక్షన్.

play19:22

కాబట్టి, మీరు మెయిన్‌కి కూడా ఇన్‌పుట్‌లను

play19:25

తీసుకునే మార్గాలు ఉన్నాయి.

play19:27

మేము దానిని తర్వాత తరగతిలో కవర్ చేస్తాము.

play19:32

కాబట్టి, మెయిన్ ఒక ఫంక్షన్ మరియు

play19:35

పవర్ కూడా ఒక ఫంక్షన్.

play19:38

printf మరియు scanf లు కూడా ఫంక్షన్ మరియు మొదలైనవి.

play19:47

కాబట్టి, నేను కొద్దిగా భిన్నమైన ఉదాహరణను

play19:51

చూపించాలనుకుంటున్నాను.

play19:52

ఇక్కడ మనం లూప్ లోపల అదే పవర్ ఫంక్షన్‌ని

play19:57

ఉపయోగిస్తాము.

play19:58

ఇక్కడ Int పవర్ ఉంటుంది.

play20:01

ఈ పవర్ ఫంక్షన్ ఫలితాన్ని గణిస్తుంది, అది

play20:06

తిరిగి వస్తుంది.

play20:08

కాబట్టి, మీరు లూప్ నుండి వచ్చిన i ని

play20:14

కలిగి ఉన్నారు, 3 పవర్ i, పవర్ ఫంక్షన్ నుండి

play20:22

వచ్చేది, - 4 పవర్ i, పవర్ ఫంక్షన్ నుండి

play20:28

వచ్చేది, printf దానికి అవసరమైన అన్ని విలువలను

play20:36

కలిగి ఉంటుంది, ఇది స్క్రీన్‌పై విషయాలను

play20:43

ప్రింట్ చేస్తుంది.

play20:46

ఆపై కంట్రోల్ ఈ స్థానానికి వస్తుంది.

play20:53

ఈ సమయంలో, ఇది తనిఖీ చేయమని చెబుతుంది,

play21:02

ఫర్ లూప్ చివరకి వెళ్లండి, ఇది i + +

play21:15

. కాబట్టి, మీరు i + + అయిన పోస్ట్ లూప్

play21:30

ఫంక్షన్‌ని చేయాలి.

play21:33

i < 20 ఉన్నాదో లేదో మళ్లీ తనిఖీ చేయండి,

play21:39

కాబట్టి, i = 1 అయ్యి ఉండేది.

play21:42

. ఇది ఇప్పటికీ 20 కంటే

play21:45

తక్కువగా ఉంది, మళ్లీ printf ఉన్న ఈ లైన్‌కు

play21:51

వస్తుంది.

play21:52

ఈ సమయంలో, ఇది రెండు ఫంక్షన్ కాల్‌లను

play21:59

చేస్తుంది, ఇది ఆర్గ్యుమెంట్‌లను పొంది, స్క్రీన్‌పై

play22:05

విషయాలను ప్రింట్ చేస్తుంది, ఫర్ స్టేట్‌మెంట్

play22:10

ముగింపుకు తిరిగి వస్తుంది, ఆ సమయంలో

play22:16

మీరు మళ్లీ i ని ఇంక్రిమెంట్ చేయండి.

play22:20

కాబట్టి, ఇది కొంచెం సంక్లిష్టమైన కంట్రోల్

play22:23

ఫ్లో.

play22:24

మీకు లూప్‌లు ఉన్నాయి మరియు మీకు ఇక్కడ

play22:27

వివిధ ఫంక్షన్ కాల్‌లు ఉన్నాయి.

play22:29

కాబట్టి, i = 3 తో చేసిన ఈ ఉదాహరణను తీసుకుందాం.

play22:37

కాబట్టి, మనం ఏదో ఒక సమయంలో, లూప్‌లో

play22:44

i = 3 గా ఉండేది, అది ఎలా జరిగిందో, ఎలా

play22:51

జరిగేదో చూద్దాం.

play22:53

i = 3కి సమానం అయినప్పుడు, printf పవర్ ని కాల్ చేస్తుంది.

play23:10

పవర్ , ఆ సమయంలో, ఆ బదిలీ ఈ విభాగానికి

play23:17

వెళుతుంది మరియు మీరు 3 పవర్ iని కలిగి

play23:24

ఉన్నందున, ఈ సందర్భంలో 3 పవర్ 3, అంటే 27, ఫలితం

play23:32

తిరిగి వస్తుంది మరియు అది తాత్కాలిక

play23:37

ప్లేస్ హోల్డర్. 27 తిరిగి వస్తుంది,

play23:42

మీకు ఇప్పటికే ఉన్న i ఉంది మరియు మీకు

play23:48

27 ఉన్నాయి.

play23:50

కాబట్టి, మీకు రెండు పారామీటర్‌లు సిద్ధంగా

play23:53

ఉన్నాయి.

play23:54

printfకి, ప్రింట్ చేయడానికి ఇంకా ఒక పారామీటర్

play23:59

అవసరం.

play24:00

కాబట్టి, ఆ సమయంలో, ఇది పవర్ అని మీరు

play24:05

చూస్తారు, అది మూల్యాంకనం చేయబడుతుంది.

play24:08

ఫలితం= - 64, అది printf కి విలువగా తిరిగి వస్తుంది.

play24:15

ఈ సమయంలో మీకు 3, 27 మరియు - 64 ఉన్నాయి,

play24:22

printf లో ప్రింట్ చేయాల్సిన ప్రతిదీ ఉంది.

play24:27

కాబట్టి, printf ఫంక్షన్ కాల్ చేయబడుతుంది,

play27:11

ఆ సమయంలో మీరు 3, 27ని ప్రింట్ చేస్తారు.

play33:31

కాబట్టి, స్క్రీన్‌పై 3 స్పేస్ 27 స్పేస్

play38:57

- 64 అని ప్రింట్ చేసి, ఆపై మీరు iలో తదుపరి

play46:11

పునరావృతానికి వెళ్లడానికి సిద్ధంగా ఉన్నారు.

Rate This

5.0 / 5 (0 votes)

Related Tags
Programming ConceptsFunction BasicsControl FlowMain FunctionSub-tasksParameter PassingReturn ValuesCode ExecutionLoops UsageTechnical TutorialProgramming Education