C Programming Flashcards

1
Q

TRUE/FALSE: C is a portable language. (Bonus: What does portable mean?)

A

TRUE. C can be run across a variety of different environments without much modification.

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

TRUE/FALSE: A variable is volatile (and should use the keyword) if it should be optimized by the compiler for efficiency, since it’s going to change a lot.

A

FALSE: Volatile variables should not be optimized by the compiler.

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

What is the type of the variable foo in the following declaration:

const char * const foo [] = {
“abc”, “xyz”
}

A

An array of constant pointers to strings (pointers to characters).

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

I want to write code that uses a variable count to store the number of times a function foo() has been run. What keyword should I use to store count?

A

static. Will be initialized to 0, and will remain in scope throughout the code’s duration.

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

I want to write a single debug variable so that I can include print statements while developing but turn them off easily on release. What keyword should I use for debug?

A

extern. This way, I can store the debug variable in a “config” file and access it without much hassle.

Notably, you can just use header files for this instead. And probably should.

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

Which part of the following variable declaration is the declarator?

const char * bar = “abc”;

A

bar. The name of the variable.

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

TRUE/FALSE: The following code will compile without error (assume headers and everything unseen are correct):

int foo = 3;
int bar = ++foo;

A

TRUE.

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

TRUE/FALSE: Do-while loops exist in C.

A

TRUE.

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

Define scope.

A

Where the item is accessible in the program.

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

Define liveliness.

A

How long the variable remains in memory during execution.

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

Why do we use macros and inline assembly?

A

To access instructions that can’t work in regular functions.

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

TRUE/FALSE: Obfuscation is the practice of using functions, modules, and different files to manage the complexity of a large program.

A

FALSE: This describes abstraction, not obfuscation.

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

TRUE/FALSE: Obfuscation is a good way to hide information from users who call your code.

A

FALSE: Obfuscation makes code hard to manage; It does not describe the process of calling it directly (it might make understanding its general purpose more difficult).

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

TRUE/FALSE: Comments are the best way to make sure your code is readable.

A

FALSE: Writing clean code is the best way; Comments help good code but don’t make up for bad code.

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