Jul 1, 2024
#include <stdio.h>
int main(void) {
printf("Hello, world\n");
return 0;
}
#include <stdio.h>
, int main(void)
, {}
printf
as function equivalent to Scratch's 'say' block.\n
for new line and ;
to signal end of statement.make
command)../program_name
(equivalent to clicking an icon).cs50.dev
(cloud-based environment with VS Code).cs50.h
for simplified functions (e.g., get_string
).#include <cs50.h>
#include <stdio.h>
int main(void) {
string name = get_string("What's your name?\n");
printf("Hello, %s\n", name);
}
if (x < y) {
printf("x is less than y\n");
}
if (x < y) {
printf("x is less than y\n");
} else if (x > y) {
printf("x is greater than y\n");
} else {
printf("x is equal to y\n");
}
int counter = 0;
counter++;
counter--;
const int N = 3;
int i = 3;
while (i > 0) {
printf("meow\n");
i--;
}
for (int i = 0; i < 3; i++) {
printf("meow\n");
}
int n;
do {
n = get_int("Size: ");
} while (n < 1);
ls
, mv
, rm
, mkdir
, rmdir
).Overflow example: int x = 2147483647; // Max int
x++; // Results in overflow to -2147483648
float y = 1.0 / 3.0;
printf("%.20f\n", y); // Reveals imprecision in representation
Welcome to CS50! 🎉