- Related Questions & Answers
- Add 1 to a number represented as linked list?
- Add 1 to a number represented as a linked list?
- Add 1 to number represented as array (Recursive Approach)?
- Add 1 to the number represented as array (Recursive Approach)?
- Program to find number of bit 1 in the given number in Python
- How to find the missing number in a given Array from number 1 to n in Java?
- Count number of bits changed after adding 1 to given N in C++
- How to add +1 to existing MySQL values?
- How to add 1 day to a Date in iOS/iPhone?
- Find all combinations that add upto given number using C++
- Java Program to generate custom random number -1 or 1
- Java program to add a given time to a particular date
- How add 1 day to Date in swift?
- Java Program to add leading zeros to a number
- How to validate a given number in JavaScript?

- Selected Reading
- UPSC IAS Exams Notes
- Developer's Best Practices
- Questions and Answers
- Effective Resume Writing
- HR Interview Questions
- Computer Glossary
- Who is Who

A program to add 1 to a given number increments the value of the variable by 1 . This is general used in counters.

There are 2 methods to increase that can be used to increase a given number by 1 −

Simple adding of one to the number and reassigning it to the variable.

Using increment operator in the program.

This method takes the variable, add 1 to it and then reassigns its value.

#include <stdio.h> int main(void) { int n = 12; printf("The initial value of number n is %d \n", n); n = n+ 1; printf("The value after adding 1 to the number n is %d", n); return 0; }

The initial value of number n is 12 The value after adding 1 to the number n is 13

This method uses the increment operator to add 1 to the given number. This is a shorthand trick to add 1 to a number.

#include <stdio.h> int main(void) { int n = 12; printf("The initial value of number n is %d \n", n); n++; printf("The value after adding 1 to the number n is %d", n); return 0; }

The initial value of number n is 12 The value after adding 1 to the number n is 13

Advertisements