C basics Flashcards

1
Q

Variables

A

int myNum = 15;

int myNum2; // do not assign, then assign
myNum2 = 15;

int myNum3 = 15; // myNum3 is 15
myNum3 = 10; // myNum3 is now 10

float myFloat = 5.99; // floating point number
char myLetter = ‘D’; // character

int x = 5;
int y = 6;
int sum = x + y; // add variables to sum

// declare multiple variables
int x = 5, y = 6, z = 50;

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
2
Q

constants

A

const int minutesPerHour = 60;
const float PI = 3.14;

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
3
Q

access string

A

char greetings[] = “Hello World!”;
printf(“%c”, greetings[0]);

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
4
Q

modify string

A

char greetings[] = “Hello World!”;
greetings[0] = ‘J’;

printf(“%s”, greetings);
// prints “Jello World!”

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
5
Q

Another way to create a string

A

char greetings[] = {‘H’,’e’,’l’,’l’,’\0’};

printf(“%s”, greetings);
// print “Hell!”

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
6
Q

Creating String using character pointer (String Literals)

A

char *greetings = “Hello”;
printf(“%s”, greetings);
// print “Hello!”

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
7
Q

condition

A

int time = 20;
if (time < 18) {
printf(“Goodbye!”);
} else {
printf(“Good evening!”);
}
// Output -> “Good evening!”
int time = 22;
if (time < 10) {
printf(“Good morning!”);
} else if (time < 20) {
printf(“Goodbye!”);
} else {
printf(“Good evening!”);
}
// Output -> “Good evening!”

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
8
Q

Ternary operator

A

int age = 20;
(age > 19) ? printf(“Adult”) : printf(“Teenager”);

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
9
Q

Switch

A

int day = 4;

switch (day) {
case 3: printf(“Wednesday”); break;
case 4: printf(“Thursday”); break;
default:
printf(“Weekend!”);
}
// output -> “Thursday” (day 4)

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
10
Q

While Loop

A

int i = 0;

while (i < 5) {
printf(“%d\n”, i);
i++;
}

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
11
Q

Do/While Loop

A

int i = 0;

do {
printf(“%d\n”, i);
i++;
} while (i < 5);

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
12
Q

For Loop

A

for (int i = 0; i < 5; i++) {
printf(“%d\n”, i);
}

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
13
Q

Break out of the loop Break/Continue

A

break out of the loop when i is equal to 4 for (int i = 0; i < 10; i++) {
if (i == 4) {
continue;
}
printf(“%d\n”, i);
}
Example to skip the value of 4
for (int i = 0; i < 10; i++) {
if (i == 4) {
continue;
}
printf(“%d\n”, i);
}

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
14
Q

While Break

A

int i = 0;

while (i < 10) {
if (i == 4) {
break;
}
printf(“%d\n”, i);

i++;
}

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
15
Q

While continue

A

int i = 0;

while (i < 10) {
i++;

if (i == 4) {
continue;
}
printf(“%d\n”, i);
}

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
16
Q
A
17
Q
A