You are on page 1of 4

Checklist:

C
Inline functions
RTOS - need to develop and learn.
GIT
Linux - kernel, modules, general info
Android - if possible

Links
Time complexity: http://www.geeksforgeeks.org/analysis-of-algorithms-set-4-analysis-of-
loops/

C Programming
● Lines starting with # (includes also) are processed by the preprocessor. Preprocessor is a program
invoked by the compiler. The contents of include file is copied to the current file by preprocessor.
● It is never a good idea to use “void main()” or just “main()” as it doesn’t confirm standards. Always use
int main()
● Angular brackets < and > instruct the preprocessor to look in the standard folder where all header files
are held. Double quotes “ and “ instruct the preprocessor to look into the current folder and if the file is
not present in current folder, then in standard folder of all header files.
● When we use define for a constant, the preprocessor produces a C program where the defined
constant is searched and matching tokens are replaced with the given expression.
● The macros can take function like arguments, the arguments are not checked
for data type.
● The macro arguments are not evaluated before macro expansion. So brackets
should be used as otherwise output can be different than expected.
● A token passed to macro can be converted to a sting literal by using # before it.
include <stdio.h>
#define get(a) #a
int main()
{
// GeeksQuiz is changed to "GeeksQuiz"
printf("%s", get(GeeksQuiz));
}
// Output: GeeksQuiz

● The macros can be written in multiple lines using ‘\’. The last line doesn’t need to
have ‘\’.
● The macros with arguments should be avoided as they cause problems
sometimes.
● The tokens passed to macros can be concatenated using operator ## called
Token-Pasting operator.
#include <stdio.h>
#define merge(a, b) a##b
int main()
{
printf("%d ", merge(12, 34));
}
● A token passed to macro can be converted to a sting literal by using # before it.
#include <stdio.h>
#define get(a) #a
int main()
{
// GeeksQuiz is changed to "GeeksQuiz"
printf("%s", get(GeeksQuiz));
}
// Output: GeeksQuiz

● There are some standard macros which can be used to print program file
(__FILE__), Date of compilation (__DATE__), Time of compilation (__TIME__)
and Line Number in C code (__LINE__)
● In C, if a macro is not defined, the pre-processor assigns 0 to it by default
● After the pre-processing of a C program, a .i file is generated which is passed to the
compiler for compilation.
● The pragma directive is used to access compiler-specific preprocessor extensions. A
common use of #pragma is the #pragma once directive, which asks the compiler to
include a header file only a single time, no matter how many times it has been imported.
● Source lines that should be handled by the preprocessor, such as #define
and #include are referred to as preprocessor directives. Another C
construct, the #pragma directive, is used to instruct the compiler to use
pragmatic or implementation-dependent features.
● #pragma GCC warning "some message"
● #pragma GCC error "some message"
● #pragma GCC poison printf -> using printf will show an error

● The left shift and right shift operators should not be used for negative
numbers
● If the number is shifted more than the size of integer, the behaviour is
undefined. For example, 1 << 33 is undefined if integers are stored using 32
bits.
● The bitwise XOR operator is the most useful operator from technical
interview perspective. “Given a set of numbers where all elements occur
even number of times except one number, find the odd occuring number”
This problem can be efficiently solved by just doing XOR of all numbers.

// Function to return the only odd occurring element
int findOdd(int arr[], int n) {
int res = 0, i;
for (i = 0; i < n; i++)
res ^= arr[i];
return res;
}

● The & operator can be used to quickly check if a number is odd or even.
The value of expression (x & 1) would be non-zero only if x is odd,
otherwise the value would be zero.
● Some data types like char , short int take less number of bytes than int, these
data types are automatically promoted to int or unsigned int when an operation is
performed on them. This is called integer promotion.
● Compiler converts a C program into an executable. There are four phases for a
C program to become an executable:
1. Pre-processing
2. Compilation
3. Assembly
4. Linking

● By executing below command, We get the all intermediate files in the current
directory along with the executable.
○ $gcc –Wall –save-temps filename.c –o filename

● Preprocessing: This is the first phase through which source code is passed. This
phase include:
○ Removal of Comments
○ Expansion of Macros
○ Expansion of the included files.

The preprocessed output is stored in the filename.i.


● The next step is to compile filename.i and produce an; intermediate compiled
output file filename.s.
● The filename.s is taken as input and turned into filename.o by assembler. This
file contain machine level instructions. At this phase, only existing code is
converted into machine language, the function calls like printf() are not resolved.
● Linking:
● Asd
● Asd
● Sad
● Sad
● Sad
● Sad
● Sad
● Sad

● Asd
● Sad






● asdsa
● Asd

You might also like