0% found this document useful (0 votes)
4 views5 pages

Functions - 5 Marks: Function Prototype Function Function Call Return Statement

The document provides an overview of functions in C, detailing their components, categories based on arguments and return values, and memory management concepts. It also covers advanced topics such as recursion, nesting functions, nested structures, pointers to structures, and the distinction between local and global variables. Additionally, it explains the use of operators for accessing structure members.

Uploaded by

eliyaz
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)
4 views5 pages

Functions - 5 Marks: Function Prototype Function Function Call Return Statement

The document provides an overview of functions in C, detailing their components, categories based on arguments and return values, and memory management concepts. It also covers advanced topics such as recursion, nesting functions, nested structures, pointers to structures, and the distinction between local and global variables. Additionally, it explains the use of operators for accessing structure members.

Uploaded by

eliyaz
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
You are on page 1/ 5

1.

Functions – 5 Marks

In C, a function is a set of statements grouped together to perform a specific task, promoting


modularity and code reusability. Functions are defined with a specific syntax:

Example :

Key Components :
1. Function Prototype: Declares the function (e.g., int sum(int, int);).
2. Function Definition: Contains the code (e.g., int sum(int a, int b) { return a + b; }).
3. Function Call: Executes the function (e.g., sum(10, 20);).
4. Return Statement: Returns a value (e.g., return a + b;).

2. Categories – 5 Marks

In C programming, functions can be categorized into four types based on their arguments and
return values. These categories are:
1. Function without Arguments and without a Return Value:
This function neither takes input nor returns any value. It performs a task independently. For
example:

 Here, displayMessage() simply prints a message without requiring input or returning output.
2. Function with Arguments and without a Return Value:
This function Takes input, no output.Example:
5. Here, displaySum() takes two integers and prints their sum.
3. Function without Arguments and with a Return Value:
This function does not take input but returns output. Example:

6. Here, getFive() returns the integer 5 without needing any arguments.


4. Function with Arguments and with a Return Value:
This function takes Takes input & returns output. Example:

7. Here, sum() takes two integers, adds them, and returns the result.

3. Introduction to Memory Management (5 Marks)

Memory management in C involves allocating and managing memory for variables during program
execution. It uses storage classes and pointers to control scope, lifetime, and access.
 Storage Classes:

o Automatic (auto): Local to a block, destroyed after execution (e.g., auto int x;).

o External (extern): Global, shared across files (e.g., extern int a;).

o Static: Retains value across calls, local/global scope (e.g., static int count = 0;).

o Register: Stored in CPU registers for speed (e.g., register int i;).
 Variables:

o Local: Limited to a function (e.g., int x = 5; inside main()).

o Global: Accessible throughout the program (e.g., int a = 20; outside functions).
Example :
4. Array of Structures - 5 Marks

An array of structures in C allows storing multiple instances of a structure under a single name.
Each element is a structure with its own members.
 Syntax:

8. Accessing: Use the dot operator (.) for members (e.g., array[i].member).
Example :-

9. Use: Ideal for managing related data (e.g., student records).

1. Recursion - 2 Marks

Recursion in C occurs when a function calls itself to solve a problem by breaking it into smaller
instances. The document mentions a recursive example with a base condition (n == 0) and a
recursive case (n + sum(n-1)). For instance, a function to calculate the sum of numbers from 1 to
n:
2. Nesting Function - 2 Marks

In C, nesting of functions refers to calling one function from within another, not defining a function
inside another (which isn’t allowed). The document explains this with an example:

3. Nested Structures (2 Marks)

Nested structures in C involve defining one structure inside another to represent hierarchical data.
The document states:

Here, struct Event contains struct Date as a member, allowing organized storage of related data
like event details.
4. Structure of Pointer in C - 2 Marks

A pointer to a structure in C stores the address of a structure variable. The document provides:

Members are accessed using the arrow operator (->): ptr->x = 10; modifies point1.x. This enables
efficient structure manipulation.
5. Local and Global Variables - 2 Marks
1.Local Variables: Declared inside a function, accessible only within it. Example from the
document:
 p is destroyed when main() ends.
2. Global Variables: Declared outside functions, accessible everywhere. Example:

 a can be used in test() and main().

6. Operators - 2 Marks
 Dot Operator (. ): Accesses structure members directly. Example:

 Arrow Operator (->): Accesses members via a pointer. Example:

You might also like