Monday, May 24, 2010

C ,Unix Questions ..answers required?

Hi Guys


i went an interview..i want your inputs on following





1 How do we reverse a singly linked list with non recursive version and only using a single pointer





2 In unix how do i print only the directories name with ls command i mean without using something like this


ls - l | awk {'printf $9'}





3 char *str="hello"


foll are the statements


a) str[2]='f';


b) strcpy(str,"Hi");


c) str="String"





Which of the above is error prone and why


4 how do i print the name of a variable in C or C++


for eg


int i,,j


"variables name are : %d %d",some code


one approach is we take pointers to these variables but even then how can i print names of these variables pointed to by these pointers





5 there is an exe in unix lets say Prog either it can give some output or it may produce some errors


we want the foll


output -%26gt; file a


errors if any -%26gt; file b


output and error in file c in the sequential order


Output 1


Error 1


Output 2


Error 2


All 3 redirection in 1 statemeant

C ,Unix Questions ..answers required?
well... the exact answers won't help you much, because it is unlikely, you'll get the same questions on your next interview.


Here are some pointers to how you can get answers to questions like these on your own:


1) get yourself a good algorithm book. Like Knuth or Wirth. You can find those in any library.


2) man ls


3) Read Kernigan's and Ritchie's "The C programming language" (found in libraries everywhere too). It should get you through most of interviews.


4). Not possible. You'll now that after you are done with #3


5) man tee; man sh;
Reply:For Point 2 :


Try This :





ls -al | grep ^d.


I don't remember much of C ( did it around 5 years back ) But for 3 , I think there is problem in


c) Str="String" - the Pointer Variable seems to be erraneously assigned.
Reply:Answers required? That's unusual, most people only post questions in the hope that they will be ignored.





Rawlyn.


No comments:

Post a Comment