About Lesson
Integer:
In C, the int data type is used to represent integer values. It is one of the primary data types and is commonly used for variables that store whole numbers. The size of an int is platform-dependent; on most modern systems, it is typically 4 bytes.
Example:
#include <stdio.h>
int main() {
// Declaration and initialization of integer variables
int number1 = 10;
int number2 = -5;
int sum, product;// Performing arithmetic operations
sum = number1 + number2;
product = number1 * number2;// Displaying the values and results
printf(“Number 1: %dn”, number1);
printf(“Number 2: %dn”, number2);
printf(“Sum: %dn”, sum);
printf(“Product: %dn”, product);return 0;
}
Output:
Number 1: 10
Number 2: -5
Sum: 5
Product: -50
Explanation of code:
- #include <stdio.h>: This line includes the standard input-output library for functions like printf.
- int main(): The main function, where the program execution begins.
- int number1 = 10; and int number2 = -5;: Declaration and initialization of integer variables.
- int sum, product;: Declaration of two more integer variables without initialization.
- sum = number1 + number2; and product = number1 * number2;: Performing arithmetic operations.
- printf(“Number 1: %dn”, number1);: Printing the value of number1 using the %d format specifier.
- Similarly, the values of number2, sum, and product are printed using printf.
- return 0;: Indicates successful program execution.