0% found this document useful (0 votes)
20 views2 pages

C Functions: Key Concepts and Examples

The document provides an overview of functions in C language, covering their purpose, syntax, declaration, definition, and calling. It explains parameter passing methods, variable scope, storage classes, and recursive functions with examples. Key concepts include function prototypes, return statements, and the distinction between local and global variables.

Uploaded by

Harsha Vardhan
Copyright
© All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
20 views2 pages

C Functions: Key Concepts and Examples

The document provides an overview of functions in C language, covering their purpose, syntax, declaration, definition, and calling. It explains parameter passing methods, variable scope, storage classes, and recursive functions with examples. Key concepts include function prototypes, return statements, and the distinction between local and global variables.

Uploaded by

Harsha Vardhan
Copyright
© All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd

C Language: Functions - Study Notes

1. Introduction to Functions

Functions help in organizing code, improving reusability, and maintaining clarity. Syntax: ReturnType

FunctionName(ParameterList);

2. Function Declaration / Prototype

This is a forward declaration that tells the compiler about the function name, return type, and parameters.

Example: int add(int, int);

3. Function Definition

Contains the body/logic of the function.

Example:

int add(int a, int b) {

return a + b;

4. Function Call

Calling a function executes its body.

Example:

int result = add(3, 4);

5. Return Statement

Used to return a value from the function.

Example:

return a + b;
C Language: Functions - Study Notes

6. Passing Parameters

Call by Value: Copies of variables are passed.

Call by Reference: Pointers are used to modify the original variables.

Example (Reference): void change(int *x) {

*x = 10;

7. Scope of Variables

Local: Declared inside a function/block.

Global: Declared outside all functions and accessible everywhere.

8. Storage Classes

Determine the scope, lifetime, and visibility of variables.

Types: auto, register, static, extern.

Example: static int count = 0;

9. Recursive Functions

A function that calls itself. Must include a base case.

Example:

int factorial(int n) {

if (n == 0) return 1;

else return n * factorial(n - 1);

You might also like