Starting Flashcards
What are some of the differences between Java and C?
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
Some more differences between C and java?
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
Which are the 2 compilers used for C?
gcc and clang
How to compile a file world.c in both gcc and clang?
gcc world.c -std =c90
clang world,c -std=c99
what are the different compiler options and what are their uses?
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.
What are the 2 stage compilation for gcc?
Compilation using the -c flag
Linking using the -o flag
What is the size of char and is it implementation dependent?
The size of char on any computer will be 8
What is the range of signed and unsigned chars
Unsigned chars: {0…255}
Signed chars: {-128….127}
What is the order of the size of the types?
Which all data types are signed/unsigned by default?
The order is as follows
char < short < int < long < long long
Every type is signed by default except for chars
What variables are initialized to 0.
Only global variables are initialized to 0
What are print modifiers for float, shortest of %f,%e
float: %f
shortest of %f, %e: %g
Print modifiers for hex, octal, long int and double
Hex: %x,
Octal: %o
long int: %li
double: %lf
What to watch out for when using the print function:
The compilers don’t check to see if the number of type modifiers is equal to the number of arguments to be output.
Precedence of operators
- Assignment is the lowest
- * / % are all equal
- relational operators > == and !=
- ++–(cast) this is evaluated from left to right
- addition and subtraction > relational operators