Computer Science Study Guide: Problem Solving Through C Unit 06 Functions Notes Set 01
Review targeted academic resources with the Problem Solving Through C Unit 06 Functions Notes Set 01. Built according to official standards for the 2026-27 term, these downloadable Computer Science study materials support effective daily practice and deeper conceptual understanding for Programming in C.
Download Programming in C Study Material PDF
Access the complete useful resource PDF for Computer Science below. Regular practice with these targeted academic notes builds familiarity with complex topics and helps secure higher marks in final school evaluations.
This page covers the top-down approach to problem solving, modular programming and the idea of a function in C, including the standard library and header files. It explains function prototypes, definitions, formal and actual parameters, return types, calling functions, call by value and call by reference, recursion and passing arrays to functions.
Top-down Approach of Problem Solving
There are three general approaches to writing a program:
Top down - In the top down approach one starts with the top-level routine and move down to the low level routine.
Bottom up - The bottom-up approach works in the opposite direction on begins with the specific routines, build them into progressively more complex structures, and end at the top- level routine.
Ad hoc - The ad hoc approach specifies no predetermined method. C as a structured language lends itself to the top down approach. The top down method can produce clean readable code that can easily be maintained
Top-down approach
A top-down approach also helps one to clarify the overall structure and operation of the program before one code the low-level functions.
The top down method starts with a general description and works towards specifics.
In fact a good way to design a program is to define exactly what the program is going to do at the top level.
Each entry in the list should contain only one functional unit.
A functional unit can be thought of as a black box that performs a single task.
Modular Programming and Functions
Modular programming
Modular programming is a style that adds structure and readability to the program code.
It may not make much difference on small projects, but as one starts to work on something bigger it can make the code much easier to read and maintain.
Structuring the code is a simple task of splitting the program into manageable chunks so that each part is self-contained.
By creating these self-contained modules, one can focus on programming each part.
Once one is satisfied that one bit is working, one can then move to the next module with the confidence, whatever one does elsewhere will not have an on effect on other modules that one has already written.
What is a function?
A function is a named, independent section of C code that performs a specific task and optionally returns a value to the calling program.
A function is named. Each function has a unique name.
By using the name in another part of the program, one can execute the statements contained in the function.
This is known as calling the function.
A function can be called from within any other function.
A function is independent.
A function can perform its task without interference from or interfering with other parts of the program.
General form of a function
#include <stdio.h>
void function_name()
{ /* step 1: control passes here when the function is called */
......
......
} /* step 2: control returns to the point after the call */
int main()
{
......
function_name(); /* function call */
......
}Standard C Library
A collection of reusable functions (code for building data structures, code for performing math functions and scientific calculations, etc.,).
Which will save C programmers time especially when working on large programming projects.
The C Library is part of the ANSI (American National Standard Institute) for the C Language.
The C programs can call on a large number of functions from the standard C library.
These functions perform essential services such as input and output.
They also provide efficient implementations of frequently used operations.
Many macros and type definitions accompany these functions and help them to make better use of the standard C functions.
Standard Library of C functions
C Standard library functions or simply C Library functions are inbuilt functions in C programming.
Function prototype and data definitions of these functions are written in their respective header file.
For example: If you want to use printf() function, the header file < stdio.h > should be included.
/* If you write the printf() statement without including the header file,
this program will show an error. */
#include <stdio.h>
int main()
{
printf("Hello World");
}There is at least one function in any C program, i.e., the main() function (which is also a library function).
This program is called at program starts.
There are many library functions available in C programming to help the programmer to write a good efficient program.
Suppose, you want to find the square root of a number.
You can write your own piece of code to find square root but, this process is time consuming and the code you have written may not be the most efficient process to find square root.
But, in C programming you can find the square root by just using sqrt() function which is defined under header file "math.h".
Use of Library Function : To Find Square root
#include <stdio.h>
#include <math.h>
int main(){
float num,root;
printf("Enter a number to find square root.");
scanf("%f",&num);
root=sqrt(num); /* Computes the square root of num and stores in root. */
printf("Square root of %.2f=%.2f",num,root);
return 0;
}Listed below are few of the standard C Libraries.
Stdio.h - Supports File Input/Output Operations.
Stdlib.h - Supports Miscellaneous declarations.
Math.h- Supports Definitions used for mathematical calculations.
String.h - Supports string functions.
Time.h- Supports system time functions.
Ctype.h - Header file "ctype.h" includes numerous standard library functions to handle characters (especially test characters).
Example Programs of frequently used standard C Libraries
#include <stdio.h>
int main()
{
int this_is_a_number;
printf( "Please enter a number: " );
scanf( "%d", &this_is_a_number );
printf( "You entered %d", this_is_a_number );
getchar();
return 0;
}Prototype of a Function
Function Prototype: return_type function_name( arg-type name-1,...,arg-type name-n);
A function prototype provides the compiler with the description of a function that will be defined at a later point in the program.
The prototype includes a return type indicating the type of variable that the function will return;it also includes the function name, which should describe what the function does.
The prototype also contains the variable types of the arguments (arg type) that will be passed to the function.
Optionally, it can contain the names of the variable that will be passed.
A prototype should always end with a semicolon.
double squared( double number ); void print_report( int report_number ); int get_menu_choice( void );
Function Definition
A function definition is the actual function.
The definition contains the code that will be executed.
The first line of a function definition, called the function header, should be identical to the function prototype, with the exception of the semicolon.
A function header shouldn't end with a semicolon.
In addition, although the argument variable names the optional in the prototype, they must be included in the function header.
Following the header is the function body, containing the statements that the function will perform.
The function body should start with an opening bracket and end with a closing bracket.
If the function return type is anything other than void, a return statement should be included, returning a value matching the return type.
return_type function_name( arg-type name-1,...,arg-type name-n)
{
/* statements; */
}The following Program demonstrates prototype of a function
#include <stdio.h>
int sum (int, int);
int main (void)
{
int total;
total = sum (2, 3);
printf ("Total is %d\n", total);
return 0;
}
int
sum (int a, int b)
{
return a + b;
}
Output:
Total is 5Formal Parameter List
Parameter
A parameter is a special kind of variable, used in a subroutine to refer to one of the pieces of data provided as input to the subroutine.
These pieces of data are called arguments.
Parameter Means Values Supplied to Function so that Function can utilize these Values.
Parameters are Simply Variables.
Difference between Normal Variable and Parameter is that "These Arguments are Defined at the time of Calling Function".
Formal Parameter
Parameter Written in Function Definition is Called "Formal Parameter".
Although formal parameters are always variables actual parameters do not have to be variables.
Example
void main()
{
int num1;
display(num1);
}
void display(int para1)
{
-----------
-----------
}Para1 is called 'Formal Parameter'.
Actual Parameter
Parameter Written In Function Call is Called "Actual Parameter".
One can use numbers, expressions, or even function calls as actual parameters.
Example
void main()
{
int num1;
display(num1);
}
void display(int para1)
{
-----------
-----------
}num1 is 'Actual Parameter'.
Parameter list
A function is declared in the following manner:
return-type function-name(parameter-list,...) { body... }Return-type is the variable type that the function returns.
This cannot be an array type or a function type.
If not given, then int is assumed.
Function-name is the name of the function.
The Function Return Type
The function return type specifies the data type that the function returns to the calling program.
The return type can be any of C's data types: char, int , long , float , or double .
One can also define a function that doesn't return a value by using a return type of void.
Given below are few examples:
int func1(...) /* Returns a type int. */ float func2(...) /* Returns a type float. */ void func3(...)
Return Type - Program
/* function returning the max between two numbers */
int max(int num1, int num2)
{
/* local variable declaration */
int result;
if (num1 > num2)
result = num1;
else
result = num2;
return result;
}Calling Functions
There are two ways to call a function.
Any function can be called by simply using its name and argument list alone in a statement, as in the following example.
If the function has a return value, it is discarded.
wait(12);
The second method can be used only with functions that have a return value.
Because these functions evaluate to a value (that is, their return value), they are valid C expressions and can be used anywhere a C expression can be used.
An expression with a return value used as the right side of an assignment statement.
In the following example, half_of() is a parameter of a function: printf("Half of %d is %d.", x, half_of(x));
First, the function half_of() is called with the value of x, and then printf() is called using the values x and half_of(x).
In this second example, multiple functions are being used in an expression: y = half_of(x) + half_of(z);
Although half_of() is used twice, the second call could have been any other function.
The following code shows the same statement, but not all on one line:
a = half_of(x); b = half_of(z); y = a + b;
Example Program
#include <stdio.h>
/* function declaration */
int max(int num1, int num2);
int main ()
{
/* local variable definition */
int a = 100;
int b = 200;
int ret;
/* calling a function to get max value */
ret = max(a, b);
printf( "Max value is : %d\n", ret );
return 0;
}Block structure
A program is made up of one or more functions, with one of these being main ().
Function is a self-contained block of program that performs a particular task.
This is the structure of function
main()
{
Message();
}
Message()
{
printf("Function Block Structure");
return;
}Example of Block Structure of program: How to create blocks using {} and their significance.
#include <stdio.h>
int main()
{
int x;
x = 0;
do
{
printf( "Hello, world!\n" );
}
while ( x != 0 );
getchar();
}Passing Arguments to a Function
To pass arguments to a function, list them in parentheses following function name.
The number of arguments and the type of each argument must match the parameters in the function header and prototype.
For example, if a function is defined to take two type int arguments, one must pass it exactly two int arguments--no more, no less--and no other type.
If one tries to pass a function an incorrect number and/or type argument, the compiler will detect it, based on the information in the function prototype.
If the function takes multiple arguments, the arguments listed in the function call are assigned to the function parameters in order.
The first argument to the first parameter, the second argument to the second parameter, and so on.
Multiple arguments are assigned to function parameters in order.
Each argument can be any valid C expression: a constant, a variable, a mathematical or logical expression, or even another function (one with a return value).
For example, if half(), square(), and third() are all functions with return values, one could write as follows:
x = half(third(square(half(y))));
The program first calls half(), passing it y as an argument.
When execution returns from half(), the program calls square(), passing half()'s return value as an argument.
Next, third() is called with square()'s return value as the argument.
Then, half() is called again, this time with third()'s return value as an argument.
Finally, half()'s return value is assigned to the variable x.
The following is an equivalent piece of code:
a = half(y); b = square(a); c = third(b); x = half(c);
Call by Reference
In this method the address of an argument is copied into the parameter.
Inside the subroutine the address is used to access the actual argument used in the call.
This means that the change made to the parameter affect the variable used to call the subroutine.
The address of x and y are passed as the parameter to the function swap().
Figure (described): function A passes the addresses (address 1, 2, 3) of its arguments to function B, so function B works on the original variables rather than on a copy.
The following Program demonstrates a call by Reference.
#include<stdio.h>
void interchange(int *num1,int *num2)
{
int temp;
temp = *num1;
*num1 = *num2;
*num2 = temp;
}
int main() {
int num1=50,num2=70;
interchange(&num1,&num2);
printf("\nNumber 1 : %d",num1);
printf("\nNumber 2 : %d",num2);
return(0);
}
Output:
Number 1 : 70
Number 2 : 50Call by Value
This method copies value of the argument into the formal parameter of the subroutine.
Therefore changes made to the parameters of the subroutines have no effect on the variable used to call it.
The value of t is passed as the parameter to the function sqr().
The following Program demonstrates call by value.
#include<stdio.h>
void interchange(int number1,int number2)
{
int temp;
temp = number1;
number1 = number2;
number2 = temp;
}
int main() {
int num1=50,num2=70;
interchange(num1,num2);
printf("\nNumber 1 : %d",num1);
printf("\nNumber 2 : %d",num2);
return(0);
}
Output:
Number 1 : 50
Number 2 : 70Recursive Functions
The term recursion refers to a situation in which a function calls itself either directly or indirectly.
Indirect recursion occurs when one function calls another function that then calls the first function.
C allows recursive functions, and they can be useful in some situations.
For example, recursion can be used to calculate the factorial of a number as shown below.
#include <stdio.h>
int factorial(unsigned int i)
{
if(i <= 1)
{
return 1;
}
return i * factorial(i - 1);
}
int main()
{
int i = 5;
printf("Factorial of %d is %d\n", i, factorial(i));
return 0;
}The following Program demonstrates recursive function.
#include <stdio.h>
int fibonaci(int i)
{
if(i == 0)
{
return 0;
}
if(i == 1)
{
return 1;
}
return fibonaci(i-1) + fibonaci(i-2);
}
int main()
{
int i;
for (i = 0; i < 10; i++)
{
printf("%d\n", fibonaci(i));
}
return 0;
}Arrays as Function Arguments
An argument is a value that the calling program passes to a function.
It can be an int, a float, or any other simple data type, but it must be a single numerical value.
It can be a single array element, but it can't be an entire array.
One can have a pointer to an array, and that pointer is a single numeric value (the address of the array's first element).
If one passes that value to a function, the function knows the address of the array and can access the array elements using pointer notation.
int largest(int x[ ], int y)
The largest() is a function that returns an int to the calling program; its second argument is an int represented by the parameter y.
The only thing new is the first parameter, int x[ ], which indicates that the first argument is a pointer to type int, represented by parameter x.
Write the function declaration and header as shown below: int largest(int *x, int y);
This is equivalent to the first form; both int x [ ] and int *x mean "pointer to int." The first form might be preferable.
The parameter represents a pointer to an array.
Of course, the pointer doesn't know that it points to an array, but the function uses it that way.
Free study material for Computer Science
Computer Science Exam Resources: Programming in C
Quick Revision Material for Programming in C
Review targeted study resources for Programming in C tailored for learners. Utilizing these structured notes and quick-revision tools ensures complete alignment with current CBSE evaluation standards.
Expert Notes and Solved Exam Questions
Designed around the official curriculum, these study guides guarantee standard compliance. Reviewing step-by-step solutions clarifies complex sub-topics within Programming in C and demystifies standard marking schemes for Computer Science evaluations.
Additional Study Resources for
Wrap up your chapter revision by testing your knowledge against standard objective question formats. Explore our full library of free, up-to-date sample papers and online assessments to secure top grades in your CBSE examinations.
FAQs
The latest 2026-27 advanced study resources for Computer Science are available for free on StudiesToday.com which includes NCERT Exemplars, high-order thinking skills (HOTS) questions, and deep-dive concept summaries.
Our exhaustive Computer Science package includes chapter wise revision notes, solved practice sheets, important formulas and Concept Maps to help in better understanding of all topics.
Yes. For , our resources have been developed to help you get better marks in school exams and also build fundamental strength needed for entrance tests including Competency Based learning.
in , students should use Active Recall method, read the concept summary, then solve the Important Questions section without looking at the answers and then check your answers.
All Computer Science study materials are provided in mobile-friendly PDF. You can download and save them on your device.
Yes, our team has ensured that all Computer Science materials for are strictly aligned with the National Education Policy (NEP) 2020 and the latest 2026-27 syllabus.