Tuesday 15 December 2020

C interview questions - part 4

 1) write a recursive function to print number from -5 to 5.


2) write a recursive function to find factorial of number.


3) string is palindrom or not

*< https://www.geeksforgeeks.org/c-program-check-given-string-palindrome/ >


4) write C program for LALR parsing 


5) explain arithmatic shift vs logical shift

< https://stackoverflow.com/questions/7622/are-the-shift-operators-arithmetic-or-logical-in-c >

note : shift operators in C are logical shift operators. you loose bits once you rotate


6) write a C program to rotate bits in number / arithmatic rotate.

< https://www.geeksforgeeks.org/rotate-bits-of-an-integer/ >


7) count number of bit needed for number 

< https://www.geeksforgeeks.org/count-total-bits-number/ >

number of bit = log2(n)+1


8) swap all bits in a number

you can construct your own program using above information.

or you can use this one < https://www.geeksforgeeks.org/swap-bits-in-a-given-number/ >


9) XOR , AND , OR truth tables


10) find repetative number in given array 

< https://www.geeksforgeeks.org/find-the-two-repeating-elements-in-a-given-array/ >


11) write a C program to find a number in given sorted array using binary search.

< https://www.geeksforgeeks.org/binary-search/ >


12) write a program to find endianness of given system.

< https://www.geeksforgeeks.org/little-and-big-endian-mystery/ >

https://stackoverflow.com/questions/12791864/c-program-to-check-little-vs-big-endian >


13) Using semphore in a C program :

https://www.geeksforgeeks.org/use-posix-semaphores-c/ >


14) Using mutex lock in C program :

 < https://www.geeksforgeeks.org/mutex-lock-for-linux-thread-synchronization/ >


15) How to pass arguments from command line in C :

< https://www.geeksforgeeks.org/command-line-arguments-in-c-cpp/ >


16) what are expressions optional in for loop ?

All the three expressions inside the for loop are optional, but the two semicolons must always be present.

  • We can omit the expression1 if the initialization is done outside the for loop.
  • If the expression2 is omitted then the condition is always true, leading to the creation of an infinite loop - a loop which never stops executing. To avoid infinite loops you should include a break or return statement within in the loop body. We discuss the break and return statements in detail in upcoming chapters.
  • We can omit the expression3 if the update expression is present inside the body of the for loop.< The for loop in C - C Programming Tutorial - OverIQ.com >



2 comments:

  1. I was searching for this ,and then found this ,it's very good honestly it helped me alot
    Thank u

    ReplyDelete