C Program to Add Two Integers


This program can be in two ways. One way is declaring and assigning the values to the variables and then calculating their sum. The other method is to declare the variables first and then the user is asked to enter two integers. Then, the sum operation is applied to both values, and the result will be displayed on the screen.

To understand this program, the learners should know about the following C programming topics:

  1. Data Types in C
  2. Variables, literals, and constants
  3. C Programming operators



int main()


int a,b;

printf("Enter two values:\n");



int sum=a+b; // ‘+’ operator is used to add the values

printf("Sum of the values is %d",sum);

return 0;




Firstly, we declare two variables that are a, b that will store the values entered by the user.

int sum=a+b; the sum of ‘a’ and ‘b’ is calculated using the ‘+’ operator and the resultant is assigned to a new variable named ‘sum’ of int data type.

Since, ‘a’ and ‘b’ both are of integer type, thus their sum will also be an integer value. That is the reason why we declare the ‘sum’ variable of the ‘int’ type.



  • Barry Allen

    A Full Stack Developer with 10+ years of experience in different domain including SAP, Blockchain, AI and Web Development.


Leave a Reply

Your email address will not be published. Required fields are marked *

This site uses Akismet to reduce spam. Learn how your comment data is processed.