---
title: "Function definition; sum of two numbers"
subject: "Computer Programming"
chapter: 6
key: "semester_1/computer_programming:function-definition-sum-two"
source: https://www.bctengineer.com/q/semester_1/computer_programming/function-definition-sum-two
site: BCT Engineering
---

# Function definition; sum of two numbers

Computer Programming · Chapter 6: User-Defined Functions

- Asked in: 2070 Chaitra, 4 marks
- Video: [▻Sum of Two Number using Function in C  Programming](https://www.youtube.com/watch?v=Dx1tsaip73c) — Computer Science and Engineering-CSE
- Answer checked by Claude Opus 5.5 (high effort) on 2026-10-14
- Page: https://www.bctengineer.com/q/semester_1/computer_programming/function-definition-sum-two
- Whole chapter: https://www.bctengineer.com/md/semester_1/computer_programming/chapter-6

## Question

Define "function definition" and write the program to find the sum of two numbers using user-defined functions.

## Short answer

A function definition is the complete code of a function with header and body. A program to sum two numbers reads two integers, calls a user-defined function int sum(int a, int b) { return a + b; }, and prints the result. For input 12 and 30, output is Sum = 42.

## Answer

A **function definition** is the complete code of a function: the header (return type, name, parameters) followed by the body in braces which performs the task. A function must be defined once, and it can be called many times.

```c
#include <stdio.h>
int sum(int a, int b);
int main(void)
{
    int x, y;
    printf("Enter two numbers: ");
    scanf("%d %d", &x, &y);
    printf("Sum = %d\n", sum(x, y));
    return 0;
}
int sum(int a, int b)
{
    return a + b;
}
```
Output for the input 12 and 30:
```text
Enter two numbers: Sum = 42
```

The prototype `int sum(int a, int b);` tells the compiler about the function; `sum(x, y)` calls it with the actual parameters `x` and `y`; the definition adds the formal parameters `a` and `b` and returns `a + b`.

## Check yourself

The answer's key points as multiple-choice questions, with the correct option and why.

1. Function definition?
   A. Declaration only
   B. Call
   C. Prototype
   D. Complete code: header and body
   Answer: D. Defined once. (Key point: Definition)

2. Prototype role?
   A. Tells compiler about function
   B. Computes
   C. Reads
   D. Returns
   Answer: A. Declaration. (Key point: Prototype)

3. a and b in sum are?
   A. Actual
   B. Formal parameters
   C. Globals
   D. Returns
   Answer: B. In definition. (Key point: Parameters)

4. 12 and 30 gives?
   A. 360
   B. 18
   C. 42
   D. 1230
   Answer: C. Sum. (Key point: Result)

## Related in Computer Programming

- [Significance of user defined functions](https://www.bctengineer.com/question.md?key=semester_1%2Fcomputer_programming%3Asignificance-user-defined-functions) — Computer Programming, chapter 6
- [Switch versus user defined function](https://www.bctengineer.com/question.md?key=semester_1%2Fcomputer_programming%3Aswitch-vs-user-function) — Computer Programming, chapter 5
- [Complex number sum via functions](https://www.bctengineer.com/question.md?key=semester_1%2Fcomputer_programming%3Astruct-complex-sum-function) — Computer Programming, chapter 8
- [GOTO types; sum of series program](https://www.bctengineer.com/question.md?key=semester_1%2Fcomputer_programming%3Afortran-goto-types-series) — Computer Programming, chapter 11
- [Sum of two matrices in FORTRAN](https://www.bctengineer.com/question.md?key=semester_1%2Fcomputer_programming%3Afortran-matrix-sum) — Computer Programming, chapter 11
- [Declaration vs definition; C program structure](https://www.bctengineer.com/question.md?key=semester_1%2Fcomputer_programming%3Adeclaration-definition-structure-of-c) — Computer Programming, chapter 3

## Related in other subjects

- [C program: sum of two 8-bit BCD numbers](https://www.bctengineer.com/question.md?key=semester_6%2Fembedded_system%3A8051-bcd-sum-c) — Embedded System, chapter 9
- [Convert user-defined type to basic type](https://www.bctengineer.com/question.md?key=semester_3%2Fobject_oriented_programming%3Auser-to-basic-conversion) — Object Oriented Programming, chapter 5
- [LandMeasure class and sum function](https://www.bctengineer.com/question.md?key=semester_3%2Fobject_oriented_programming%3Alandmeasure-class-sum) — Object Oriented Programming, chapter 4
- [8086 ALP: sum of 100 even numbers](https://www.bctengineer.com/question.md?key=semester_4%2Fmicroprocessor%3Aalp-8086-sum-even-numbers) — Microprocessor, chapter 3
