LearnC/main.c
2022-12-07 10:13:26 -05:00

44 lines
1.5 KiB
C

#include <stdio.h>
const int MINUTES_PER_HOUR = 60; // This value cannot be changed later
void types() {
// Datatypes:
int number = 16; // Whole number
float decimal = 3.1415; // Decimal number up to 7 points
double longDecimal = 3.1415926535; // Decimal up to 15 points
char letter = 'S'; // Single letter
char word[] = "Super"; // Multiple letters
// Printing different datatypes
printf("%d\n", number); // Use %d or %i to print ints
printf("%f\n", decimal); // Use %f to print floats
printf("%lf\n", longDecimal); // Use %lf to print doubles
printf("%c\n", letter); // Use %c to print chars
printf("%s\n", word); // Use %s to print strings
}
void operators() {
// Math operators
int x = 0;
x = 5; // Assigns value 5 to variable x
x += 5; // Adds 5 to the value of x. Same as x = x + 5
x -= 5; // Subtracts 5 from the value of x. Same as x = x - 5
x *= 2; // Multiplies the value of x by 2. Same as x = x * 2
x /= 2; // Divides the value of x by 2. Same as x = x / 2
x %= 2; // Returns the remainder of the value of x / 2; Same as x = x % 2
x &= 2; // TODO figure out wtf this does
x |= 2; // TODO figure out wtf this does
x ^= 2; // TODO figure out wtf this does
x >>= 2; // TODO figure out wtf this does
x <<= 2; // TODO figure out wtf this does
}
int main() {
types();
printf("Hello, World!\n");
return 0;
}