Jul 1, 2024
.c
extension (e.g., helloworld.c
).g++ --version
in command prompt.
clang --version
. If not installed: xcode-select --install
.gcc -v
and install using sudo apt-get install build-essential
.terminal -> configure default build task -> C++ (G++ Task)
.tasks.json
file within .vscode
that tells VS Code how to compile the program.#include <stdio.h>
.int main() {
printf("I like pizza\nIt's really good");
return 0;
}
run code
or manually via terminal.printf
as just print
.scanf
for simple inputs or fgets
for strings that may contain whitespaces.
// for integers
int age;
printf("How old are you?");
scanf("%d", &age);
printf("You are %d years old", age);
// for strings with white spaces
char name[25];
printf("What is your name?");
fgets(name, 25, stdin);
name[strlen(name) - 1] = '\0'; // removes newline
//
for single-line, /* */
for multi-line.\n
for newline, \t
for tab, \"
for quotes, \\
for backslash.int
, float
, char
, arrays, etc.int age = 21;
printf
to display variables.&&
): Checks if multiple conditions are true.||
): Checks if at least one condition is true.!
): Reverses the state of a condition.void birthday() {
printf("Happy Birthday!");
}
int main() {
birthday(); // calling the function
return 0;
}
int numbers[5];
int numbers[] = {1, 2, 3, 4, 5};
struct Player {
char name[50];
int score;
} player1, player2;
typedef struct Player Player;
).enum
keyword to create a type with named integer constants.
enum Day {SUN, MON, TUE, WED, THU, FRI, SAT};
enum Day today = MON;
int *p = &var;
*p