Please share it with your friends who are preparing for interview , and comment down your suggestions , or any mistake in the post.
code snippets are hosted on ideone.com. you can run code there as well.
1. What will be new average given ( old average + number of samples ) and new sample value :
New average = ( old average ) * ( old number of samples ) + new sample / ( old number of samples + 1 )
2. Read some details about C standard libraries :
< https://www.tutorialspoint.com/c_standard_library/ >
3. Remeber that strings are terminated with null character "\0" (zero) , this is how we find end of the string. In C language there is no seperate string data type , strings are created using arrays. Where as in C++ , strings are a seperate class.
also '\0'( ASCII ) is 0x00 in hex.
'0'( ASCII ) is 0x30 in hex.
one interesting string question < https://stackoverflow.com/questions/18688971/c-char-array-initialization/18688992#18688992 >
Consider below example of "strlen" vs "sizeof" below.
4. What is use of Assert for error handling in C language ???
C assert() statement is a runtime assert statement i.e it won't give you a compile time error , but it will result into runtime error when assert() statement fails.
Compile time asserts can be also written , using preprocessor directives like #if , #warning, #error or using if...else. Always remember preprocessor is invoked before compiler and linker.
Please play around with below example code , I would recommend to install codeblocks + MinGW in yout machine and try there.
5. What is use of Cygwin ( note : windows bash is going to replace Cygwin ).
< https://www.quora.com/For-what-purposes-is-cygwin-exactly-used >
6. Overflow of smaller data type:
Remeber that when you assign a "larger value" to a "smaller data type variable" overflow occurs.
Also remember that range of signed char is -128 to 127 ( negative side is more ) and unsigned char range is 0 to 255.
consider following example :
7. Rules of integer promotion and type casting in C :
This is excellent article.
< https://www.geeksforgeeks.org/integer-promotions-in-c/ >
also try this code as well:
Is integer promotion always needed ?
8. Types of Error in C :
There are 3 types of errors : compile time , link time , run time , logical/design errors.
compile time error can be syntex error or semantic error.
It's very difficult to detect design errors.
< https://www.geeksforgeeks.org/errors-in-cc/ >
example of sematic error :
int main(void) {
volatile unsigned int temp;
10 =
temp;
}
error: lvalue required as left operand of assignment.
9. what is lvalue and rvalue ??
< https://www.geeksforgeeks.org/lvalue-and-rvalue-in-c-language/ >
10. How would you avoid invalid use of assignment operator instead of comparison operator ??
consider below nasty situation and try to guess output :
to avoid this you can make rule to write VALUES/rvalue on left hand side of comparision operator. as writng rvalue on left hand side of assignment operator will result in simantic error.
You should write following way.
Please share it with your friends who are preparing for interview , and comment down your suggestions , or any mistake in the post.
code snippets are hosted on ideone.com. you can run code there as well.
Really useful to read these before interviews. Good collection of challenging questions. ~NT
ReplyDelete