Berkeley CSUA MOTD:Entry 20427
Berkeley CSUA MOTD
 
WIKI | FAQ | Tech FAQ
http://csua.com/feed/
2024/11/23 [General] UID:1000 Activity:popular
11/23   

2001/1/25-26 [Computer/SW/Languages/C_Cplusplus] UID:20427 Activity:high
1/24    At interviews, I've been asking, "Write a C program 'sum' that takes
        two integer arguments and prints out the result.  E.g., 'sum 5 12'
        should print 17 to the screen."  This is a gut check question, but
        everyone seems to have problems with one thing or the other.  Any
        ideas for a better 5-10 minute written C question?  Thanks.
        \_Ask them to construct a simple linked list using pointers. Your
        program should be a 30 second question. If people can't get that right
        then you shouldn't be hiring them. Maybe it's the way you ask the
        question.
           \_ 30 seconds eh? you must write sloppy code.
        \_ Right, no one should miss that question, so... How *exactly*
           are you phrasing it?
           \_ I phrase it just as I've written above.  Try the question
              yourself.  You have 7 minutes, you explicitly do not
              have a computer to test it on, and you do not have man
              pages or books.  Tell us whether you did it right given
              these constraints.
        \_ My favorite one is: write strcpy().  Tells you a lot about a
           person's understanding of C.
           If you want trick questions, take a look at
           http://www.xcf.berkeley.edu/help-sessions/c-tricks.html -- misha.
           \_ The alpha geek at our company notes:
                xxxxx: but the paradigm of x[y] = *(x+y) is actually used
                quite a lot...  especially when you're not sure the size of
                x in which case long x; x[5] is actually *(x + 5 * sizeof(x))
              You learn something new every day. -- Marco
                \_ Hilfinger grilled this sort of thing into us in 60c.
           \_ let us hang our heads for the xcf requiem.
        \_ what kind of problems do people have with this???
           \_ main(int argv, int argc)
              main(char **argv, int argc)
              sum = argv[1] + argv[2];
              x = (int) argv[1];
              several other bad things

              did not:
              initialize sum
              include any header files

              I don't like my question, so I'll try the strcpy() question
              next.  Thanks, misha.
                \_ You don't need header files to printf sum.  You'll get
                   a compiler warning but it will print when executed.
                   If they can't do sum(), they sure as hell can't do a
                   strcpy rewrite.  I suggest a series of 30 second questions
                   in the Hello, World or sum() realm and then give them a
                   shell, gcc, vi/emacs, and 30 minutes to write, and
                   successfully compile something more serious.  After all,
                   they *will* have a computer once they're doing their job
                   on site so why deny them that during the interview?  Just
                   another random viewpoint.  BTW, I assume this is for junior
                   level positions.
        \_ I've been in the industry for 7 years, and every time I need to use
           trivial things like fgets() I still need to look up the man page.
        \_ Knowing what the heck you are building is the hard part.  The
           programming language is the esay part.
        \_ Your question is too easy.  It should sum an arbitrary number of
           arguments from the command line.
           \_ and then compute the last digit of pi.
2024/11/23 [General] UID:1000 Activity:popular
11/23   

You may also be interested in these entries...
2012/7/19-11/7 [Computer/SW/Languages/C_Cplusplus] UID:54439 Activity:nil
7/19    In C or C++, how do I write the code of a function with variable
        number of parameters in order to pass the variable parameters to
        another function that also has variable number of parameters?  Thanks.
        \_ The usual way (works on gcc 3.0+, Visual Studio 2005+):
               #define foo(fmt, ...) printf(fmt, ##__VA_ARGS__)
           The cool new way (works on gcc 4.3+):
	...
2011/2/5-19 [Computer/SW/Languages/C_Cplusplus] UID:54027 Activity:nil
2/4     random C programming/linker fu question.  If I have
        int main() { printf("%s is at this adddr %p\n", "strlen", strlen); }
        and soda's /proc/sys/kernel/randomize_va_space is 2 (eg; on)
        why is strlen (or any other libc fn) at the same address every time?
        \_ I don't pretend to actually know the right answer to this, but
           could it have something to do with shared libraries?
	...
2006/7/13-18 [Computer/SW/Languages/C_Cplusplus] UID:43667 Activity:nil
7/13    How do you get milliseconds in C? I want to do something like:
        t1=sec;
        long_operation_that_needs_to_be_benchmarked();
        t2=sec;
        printf("This operation took %f seconds", (t2-t1));
        \_ You could try using clock() and CLOCKS_PER_SEC.
	...
2005/6/21-23 [Computer/SW/Languages/Perl] UID:38230 Activity:high
6/21    My math and/or perl fu is weak. Is there a way to get integer
        multiplication in Perl the way it's done in C? i.e. limiting
        to 32 bits. Like 1588635697 * 1117695901 = 1166976269 in C.
        \_ Can't you just multiply and then mask all but the last 32 bits?
           \_ I don't think so; that's not the same as mult overflow.
              > perl -e 'print (1588635697 * 1117695901)'
	...
2004/5/13-14 [Computer/SW/Languages/C_Cplusplus] UID:30202 Activity:very high
5/12    nCircle is looking for an experienced software engineer.  See
        /csua/pub/jobs/nCircle.sweng
        \_ so I have been doing java, and I still believe I'm an expert
           c/c++ programmer.  However, if you ask me what are
           the printf format parameters, I doubt I could tell you much
           other than %s.  So I can definitely get a book on c/c++ and
	...
2004/5/11 [Computer/SW/Languages/C_Cplusplus] UID:30157 Activity:high
5/10    Can I create arbitrary blocks of code in C without control structures?
        I really just want something I can "break" out of.
        GetLock(myLock);
        {
          rc = SomeLibraryCall();
          if (rc < 0) break; // breaks to release lock
	...
2003/9/17-18 [Computer/SW/Compilers] UID:10234 Activity:nil
9/17    For this snipet of code:
        for (i = 0; i < 3; i++) {
            printf("\n\n0x%x %d", ptr++, *ptr);
        }
        Is there anything machine dependent about the evaluation of ptr++?
        I tried this on sparc/solaris and *ptr prints out the value AFTER
	...
2002/11/18 [Computer/SW/Languages/Java, Computer/SW/Languages/Functional] UID:26574 Activity:very high
11/17   How come printf("%f\n", 1/10); returns 0.000000?
        \_ because it is? go read up on integer division.
           \_ gosh how dare you ask someone to rtfm.  how rude of you not to
              spoon feed someone on the motd.  I'll bet you're not a pine
              user either.
              \_ Gosh, how dare you correct someone on the motd without the
	...
2002/7/13-15 [Computer/SW/Languages/C_Cplusplus] UID:25351 Activity:moderate
7/13    how do i pass variables to the system in C ?  e.g.
         system("echo input is %s", argv[1]);
        results in "input is %s" but I want the system to see argv[1]
        (I know i can just use printf, but not for what i really want to do).
        \_ sprintf into array, pass array to system?
        \_ so write your own function that takes a variable number of
	...
2000/10/26-27 [Computer/SW/Unix] UID:19573 Activity:kinda low
10/25   Simple question..  In C under unix, how do I invoke the unix command
        date to create a char string which contains the present date?
           \_ actually, you should fork a process that runs date
              but has date's stdout handle to point to a handle in the
              parent proc.  yeah, you really want time(), ctime()
                \_ could I get an example ..  something like :
	...
2000/4/6 [Computer/SW/Languages/Java, Computer/SW/Languages/Perl] UID:17940 Activity:nil
4/6     C vs. Java vs. Perl comparisons:
------------------
#include <stdio.h>
#include <stdlib.h>
int fib(int num) {
    if (num==0 || num==1) {return 1;}
	...
1999/8/20 [Computer/SW/Languages/C_Cplusplus] UID:16355 Activity:high
8/19    Is it true for every "new()" there should be a matching "delete()"
        in C++?  (My bad, after the first response I relized the question was
        not specific enuf).
        More specifically,
        ...
         struct a {
	...