int, or integer, is a data type that represents whole numerical values. This means that if you are assigning an integer value, it cannot contain decimals.
Example of acceptable assignment of value:
int num1 = 1; int num2 = 42;
Example of unacceptable assignment of value:
int num1 = 1.5; //produces an error
Upon initialization, if a value is not assigned to an integer, it starts with a value of 0. Example of an int declaration that isn't assigned a value:
int num;
When assigning a value to an int, the value assignment can be a number, operation to obtain a number, a method that returns an integer or an integer property.
Examples of acceptable assignments include:
int num1 = 5 - 2; //stores 3 in num1 int num2 = num1 * 2; //takes num1 and multiplies it by 2, storing 6 in num2 int num3 = MethodReturningInt(); int num4 = Class.Property;
char c1 = ' ' char c2 = '%' char c3 = 'a'