The first session on “Cracking the Coding Interview” was all about learning what happens under the hood in the C language programming. The C language will be used as a programming language to write code in future sessions when doing Data Structure and Algorithms. The C language was chosen because everyone knows it and it is small and fast to learn, plus it provides more visibility into the hardware.
Everyone in the audience knew C language basics. We started building on top of that. Let's recap what we have learned.
What happens under the hood
When we write code then convert it to an executable and then execute it, there are multiple steps involved in that, each of these steps were discussed in great detail.

Write Code
Separating the code between header and code files. Declaration v/s Definition.
Pre-processing
The compiler looks for pre-processing tokens (#) and performs the required operation.
Compiling
Token generation generally happens twice in the C language (once during pre-processing and then during compiling)
Linking
Stdio.h has the declaration of the printf function. The actual definition comes during the linking phase. Similarly if we just declare a function and don't define it, then it will fail during linking.
Loading
When a program is loaded into memory (allocated by the OS):
- The code (machine language instructions) goes in the code area.
- Global and Static variables are allocated memory in the data area.
- Activation records of functions go in the Stack Area
- Memory that we allocate using malloc, calloc, realloc goes in the heap.
Question
What is the error in the following code?
- int x = y;
- int main()
- {
- Int y = 5;
- }
Discussed the memory snapshot when we call functions and how it is for recursive functions.
Memory stack overflow v/s Infinite Execution

Question
Why is the following code dangerous:
- int x = 0;
- int a() { x = 10; return 2; }
- int a() { x = 10; return 2; }
- int main()
- {
- int y = a() + b();
- }
Pointers are the biggest strength available to developers of the C language, it is also the biggest source of errors. There are just two operators:
- &: address of
- *: indirection (value at )
rValue v/s lValue: Probably the most important concept to understand. When a variable is defined it has both a rValue and lValue. Literals don't have a rValue. Learn more at Difference between lvalue and rvalue expressions
There are only two problems that can exist when programming using pointers:
- Memory Leaks
- Dangling pointers
Learn about then at Memory leaks and dangling pointers
Learn about Complexities
Whenever we write any code, we need to see how much time and how much memory our code is taking. There should be a standard terminology for expressing how your program performs (time taken or extra memory taken).
Why are algorithms always accessed in the terminology or "Worst Case complexity"?
How recursive functions take more memory and more time, but are still used because in some places it is easier to write code using recursion than using iteration.
What comes next
This session was just to bring everyone to the same page before getting into the actual Interview Preparation mode starting next session.
Audience Feedback

In the next session we will start with Searching problems. How to search in an Array, List, Tree, Graph and so on.
We will also talk about various sorting algorithms and compare the time and memory taken by various algorithms and where they are applicable.

kamal rawatPosted Dec 26, 2014, 1:54 AM
Sam, That is not the error, It's a typo.. Such simple questions were not asked... Actually we are trying to initialize a load-time (global) variable with a variable in the Activation Record of function main.. Now Load time variable are initialized while loading the program, and variable 'y' don't exist at load time.. Hence ERROR... That's why, As a rule Load time variable (global and static) cannot be initialized by local variable of return value of a function..
kamal rawatPosted Dec 26, 2014, 1:52 AM
sam, rValue and lValue were discussed using assignment, literals (which has only rValue and no lValue).. and pointers.. printf (which uses rValue) and scanf(which uses lValue) functions were also discussed in detail.. Purpose of this article is have a small recap.. so that those who have been part of the session can revise before coming to next session.. But yeah, for those who were not part of the session this may left lot of things unexplained..
kamal rawatPosted Dec 26, 2014, 1:49 AM
Sam, void pointers were discussed.. It was also discussed why we have specific type of pointers when all data pointers are allocated same size of memory (because dereferencing is not possible)..
Mahesh ChandPosted Dec 25, 2014, 1:39 AM
Good reviews :) and good idea to share them.
Sam HobbsPosted Dec 24, 2014, 4:38 PM
The answer to the question "What is the error in the following code?" is that int is mis-spelled, correct?
Sam HobbsPosted Dec 24, 2014, 4:37 PM
I think that definitions of variables provide a misleading description of rValue v/s lValue. An assignment statement is the appropriate way to describe them. A rValue is the right-side value of an assignment statement and a lValue is the left-side value.
Sam HobbsPosted Dec 24, 2014, 4:34 PM
I suggest talking about void pointers. They are something that beginners are likely to think is easy to use. Employers should consider them to be really, really bad unless they are truly necessary and are used carefully.
Hemant SrivastavaPosted Dec 24, 2014, 11:23 AM
Nice!
Guest UserPosted Dec 24, 2014, 6:41 AM
Nice one Kamal! You've indepth knowledge, which is very useful in solving various issues like memory leak etc.
Abhishek AroraPosted Dec 24, 2014, 5:59 AM
It was a good session sir. Very informative..