Starting Flashcards

1
Q

What are some of the differences between Java and C?

A

Java:

  • Object Oriented
  • I/O, layered IO
  • Macros are rarely used
  • Classes for namespaces

C;

  • Function oriented
  • Byte stream I/O
  • Macros are common
  • Single name space, file oriented
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
2
Q

Some more differences between C and java?

A

Java:

  • Manages the length of the array
  • Garbage collector manages the allocation and the freeing of memory

C:

  • You need to manage the length of the array on your own
  • Memory that is created on the stack is manged automatically but that which is allocated on the heap is upto the programmer to manage and free
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
3
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
4
Q

How to compile a file world.c in both gcc and clang?

A

gcc world.c -std =c90

clang world,c -std=c99

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

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

A

The different 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
6
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
7
Q

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

A

The size of char on any computer will be 8

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
8
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
9
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
10
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
11
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
12
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
13
Q
A
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
14
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
15
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
16
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

17
Q

What is the scanf function?

A

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

18
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
19
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.
20
Q
A
21
Q

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

A

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

22
Q
A
23
Q
A
24
Q
A
25
Q
A
26
Q
A
27
Q
A
28
Q
A
29
Q
A
30
Q
A