Integer
Part of the Fundamentals section of Coddy's C journey — lesson 6 of 63.
In C, integers are whole numbers without any decimal points. They are one of the most common data types you'll work with.
Declaring, initializing, and modifying integers:
int age; // Declaring
int score = 100; // Declaring and initializing
score = 90; // ModifyingPrint an integer using printf:
printf("%d", score);The int type stores whole numbers.
Challenge
EasyCreate a program that:
- Declares an integer variable named
number - Assigns the value 50 to this variable
- Prints the value of the variable using printf
Your output should look like this:
The value is: 50Cheat sheet
Integers in C are whole numbers without decimal points. Use the int data type to work with them.
Declaring, initializing, and modifying integers:
int age; // Declaring
int score = 100; // Declaring and initializing
score = 90; // ModifyingPrint an integer using printf with the %d format specifier:
printf("%d", score);Try it yourself
#include <stdio.h>
int main() {
// Declare an integer variable named 'number'
// Assign the value 50 to the variable
// Print the value using printf
return 0;
}This lesson includes a short quiz. Start the lesson to answer it and track your progress.
All lessons in Fundamentals
3Operators
Arithmetic OperatorsModulo OperatorIncrement/DecrementAssignment OperatorsRelational OperatorsLogical Operators Part 1Logical Operators Part 2Logical Operators Part 3Recap Challenge