Introduction to Templates

Easy Templates & Generic Programming
Solve in Playground →

Problem Statement

Create a function template `add(T a, T b)` that takes two arguments of type `T` and returns their sum. In `main()`, read two integers and compute their sum using `add()`. Then read two doubles, compute their sum using `add()`, and print the results.

Input Format

Two space-separated integers, followed by two space-separated doubles.

Output Format

Print 'Int: [sum]' and 'Double: [sum]' on separate lines.

Constraints

None

Sample Input

5 10 2.5 3.5

Sample Output

Int: 15
Double: 6

Explanation

Function templates allow you to write a single generic function that works with any data type, avoiding repetitive code.

Starter Code

#include <iostream>

// Write your add function template here

int main() {
    int i1, i2;
    double d1, d2;
    // Read input and use add() template
    return 0;
}

Limits

  • Time Limit: 1s
  • Memory Limit: 256MB

Embedded C Programming

Updated: March 15, 2026
Intermediate

Embedded systems rely on efficient low-level programming to interact directly with hardware. In this course, you will learn how to write practical Embedded C programs used in real microcontroller-based systems. Rather than focusing only on theory, this course follows a practice-driven approach. Each lesson includes hands-on coding exercises that simulate real firmware development tasks used