C Addition Operator

In C Programming, Addition Operator is used to find the sum of two numbers. The operator takes two operands and returns the sum of these two operands.

In this tutorial, we shall learn about Arithmetic Addition Operator and its usage with examples.

Operator Symbol

The symbol of Arithmetic Addition Operator is +.

ADVERTISEMENT

Syntax

The syntax of Addition Operator with two operands is

operand1 + operand2

When this operator is given with operands of different numeric datatypes, the lower datatype is promoted to higher datatype.

Examples

In the following program, we take two integers in a, b, and find their sum using Addition Operator.

main.c

#include <stdio.h>

int main() {
    int a = 12;
    int b = 7;
    
    int result = a + b;
    printf("Result : %d\n", result);
    
    return 0;
}

Output

Result : 19
Program ended with exit code: 0

In the following program, we take two floating point values in a, b, and find their sum using Addition Operator.

main.c

#include <stdio.h>

int main() {
    float a = 1.2;
    float b = 0.7;
    
    float result = a + b;
    printf("Result : %f\n", result);
    
    return 0;
}

Output

Result : 1.900000
Program ended with exit code: 0

In the following program, we take two numeric values of different datatypes, say an integer value in a, and a floating point value in b, and find their sum.

main.c

#include <stdio.h>

int main() {
    int a = 2;
    float b = 0.7;
    
    float result = a + b;
    printf("Result : %f\n", result);
    
    return 0;
}

Output

Result : 2.700000
Program ended with exit code: 0

Since, int is the lower datatype and float is the higher datatype, the operation a + b promotes a to float datatype.

Conclusion

In this C Tutorial, we learned how to use Arithmetic Addition Operator to find the sum of numeric values with examples.