Introduction to C Flashcards

1
Q

What is C?

A

C is a weakly, statically-typed compiled language

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

Define statically typed:

A

Variable types are known at compile time

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

Define weakly-typed:

A

Relaxed approach to typing, for example variables can be implicitly converted to a different type

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

Define compiled language:

A

Build assembly code and run it

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

Is C Object Oriented Programming?

A

NO!

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

How is memory management handled in C?

A

Memory management is handled by the programmer. Memory space must be managed and monitored.

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

What is a preprocessor?

A

Passes through the code first and makes a number of substitutions with the directives pointed at (find and replace)

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

What are the parameters of the main function?

A
  1. int argc (Number of program arguments)
  2. char* argv[] (array of program arguments)
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
9
Q

What is a declaration of definition of a variable?

A

Announcing its properties (type) and setting aside memory, but does not initialise it.

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

What happens if a variable is not explicitly set?

A

Whatever was last stored in that memory space will be stored in that variable, until redefined.

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

Can variables be redeclared in the local scope if the are defined in the global scope?

A

Variables can be redeclared in the local scope if it’s already defined in the global scope.

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

Can variables be redefined in the global scope?

A

It cannot be redefined in the global scope if it already exists in there.

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

What should we set used variables to after we don’t need them?

A

It is good practise to set the variables to 0/null after they’ve been used as there is no garbage collection in C unlike Java.

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

In C what is static (in the global scope)?

A

A static in the global scope is a variable or function that is for the private use of functions in the declaring file only

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

In C what is static (in the local scope)?

A

In the local scope a static variable is not destroyed at the end of the scope, the next time the scope is called, the previously set value will be there

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

Is there a Boolean value in C?

A

No, 0 is true and any other number is false.

17
Q

What is void and what is its size?

A

Type for functions that take/return nothing. No size

18
Q

What are the common integer types and their size?

A
  • char (8-bit)
  • short (16-bit)
  • int (32-bit)
  • long (64-bit)
  • unsigned char (8-bit)
  • unsigned short (16-bit)
  • unsigned int (32-bit)
  • unsigned long (64-bit)
19
Q

What are the floating point types and their size?

A
  • float (32-bit), works for most things
  • double (64-bit), useful for accurate computation
20
Q

Where do we declare the iterator i for loops in C?

A

We must declare int i outside the loop. But initialisation can be done inside the loop.

21
Q

What is forward declaration?

A

Declaring the function exists before it is defined, as a form of function prototype.

22
Q

What do header files store?

A

Stores all the constants, macros, system wide global variables and function prototypes for the program.

23
Q

What is the compilation process in C?

A

1.Source Code, turned into expanded code by the pre-processor
2. Compiler compiles the code into assembly code
3. Assembler turns the assembly code into object code
4. Linker turns the object code into binary executable.

24
Q

What are the two main stages of compilation?

A

Compiling
- Compile each source/implementation file (.c) int object files (.o)

Linking
-Link all individual object files into one large binary executable

25
Q

Does code ordering matter in C?

A

Yes, if something is called before it is defined it will lead to compile errors

26
Q

Are header files compiled?

A

Header files are never directly compiled, the are only included to provide necessary information to compile.

27
Q

What is the syntax to include header files?

A

include “filename.h”

28
Q

What are header guards?

A

Header guards are pre-processor directives. Used to check if a header has been already been imported in the file.

29
Q

What are the three pre-processor directives for header guards?

A
  1. If “EXAMPLE_H” is no defined:
    #ifndef EXAMPLE_H
  2. Define “EXAMPLE_H”:
    #define “EXAMPLE_H”
  3. End if:
    #endif