Starting Flashcards

1
Q

Which are the 2 compilers used for C?

A

gcc and clang

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

How to compile a file world.c in gcc?

A

gcc world.c -std =c90

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

what are the different gcc compiler options and what are their uses?

A

The different gcc compiler options are

  • -o: Name your executable
  • -g: Add in debugging information
  • -Wall: Give warnings
  • -Wextra: Give additional warnings
  • -O, O2, O3: Compiler optimization and different levels of it.
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
4
Q

What are the 2 stage compilation for gcc?

A

Compilation using the -c flag

Linking using the -o flag

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

What is the size of char and is it implementation dependent?

A

The size of char on any computer will be 8bits

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

What is the range of signed and unsigned chars

A

Unsigned chars: {0…255}

Signed chars: {-128….127}

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

What is the order of the size of the types?

Which all data types are signed/unsigned by default?

A

The order is as follows

char < short < int < long < long long

Every type is signed by default except for chars

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

What variables are initialized to 0.

A

Only global variables are initialized to 0

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

What are print modifiers for float, shortest of %f,%e

A

float: %f

shortest of %f, %e: %g

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

Print modifiers for hex, octal, long int and double

A

Hex: %x,

Octal: %o

long int: %li

double: %lf

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

What to watch out for when using the print function:

A

The compilers don’t check to see if the number of type modifiers is equal to the number of arguments to be output.

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

Precedence of operators

A
  • Assignment is the lowest
  • * / % are all equal
  • relational operators > == and !=
  • ++–(cast) this is evaluated from left to right
  • addition and subtraction > relational operators
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
13
Q

What is #include

How to include a library header file?

A

include <curl></curl>

it is preprocessor directive. These are used to insert header files into the program. These header files are given the extension .h

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

What is the scanf function?

A

The scanf function is used to read in input. It only contains conversion specifications

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

What are the things to watch out for when using scanf?

A
  • The programmer must make sure that the number of input specifiers matches the number of arguments
  • The & symbol precedes the name of the variable and the programmer must make sure that this is included.
  • Scanf also peeks at the final new line without reading it
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
16
Q

Outline how scanf works

A
  1. Scanf reads the input by matching the input specifiers with the input data given to it.
  2. it skips white spaces if necessary
  3. It reads the input until there is a mismatch in the input specifiers
  4. If everything is fine with one specifier then it moves onto the next specifier, eventually reading the whole line if nothing goes wrong.
17
Q

What are the modifers that can be used interchangeably in scanf?

A

The modifiers that can be used interchangeable are %e. %f, %g