[Search for users] [Overall Top Noters] [List of all Conferences] [Download this site]

Conference turris::vaxc

Title:VAX C Notes
Notice:READ 1.* BEFORE WRITING; USE KEYWORDS TO FIND EXISTING NOTES
Moderator:DECC::VMCCUTCHEON
Created:Sat Jan 25 1986
Last Modified:Mon Jun 02 1997
Last Successful Update:Fri Jun 06 1997
Number of topics:5611
Total number of notes:27963

5606.0. "Looking for Quiz" by HANDVG::STEVELIU () Tue Apr 22 1997 06:50

    
    if you have any Quiz that test one's understanding on C, please post
    them here. thanks.
    
    Here's one from my colleage at work :
    
    Quiz #1:
    =======
    
          Do you find anything wrong in the code below.  If yes, where and
    why?
    
    
            char mystring[] = "this is a test";
            char *string;
    
            strcpy(string,mystring);
            printf("string\n");
    
    
          ________________________________________________
    
    Looking forward to more Quiz from all the C's expert on the Net.
    
    -sl.
                                        
T.RTitleUserPersonal
Name
DateLines
5606.1This one is just too easyVESPER::VESPEROpenGL Alpha GeekTue Apr 22 1997 09:209
>    Here's one from my colleage at work :
                        ^^^^^^^^

Keyword mispelled, should be colleague.

:-)

Andy V

5606.2Look Around -- You Have Several Thousand Questions Here...XDELTA::HOFFMANSteve, OpenVMS EngineeringTue Apr 22 1997 11:2915
    
:    if you have any Quiz that test one's understanding on C, please post
:    them here. thanks.

   I'll assume you are looking to create a document or test for a
   customer.  If so, this is the older VAX C notes conference, but
   it contains *piles* of C questions from internal and external folks.
   Also of interest will be the more current DEC C notes conference (at
   TURRIS::DECC).  All manner of obvious -- and obscure -- questions can
   be found here in these conferences.

   One of the most common (subtle) C programming errors is this:

	x[i++] = y[i];

5606.3quiz to enhance your C-skillHANDVC::STEVELIUWed Apr 23 1997 05:2636
    
    
    
    
    Yes, x[i++] = y[i] is a good one.
    
    Very nice, this is exactly my intention, anyone put up a quiz which can
    trap common errors made by C programmers, it is fun and educational.
    
    Here's another quiz from my colleague :
    
           memory content by byte (all in Hexidecimal)
    
           address      content
           81009040      8A
           81009041      7D
           81009042      45    <-   x is pointing at here
           81009043      3A
           81009044      6F
           81009045      33
           81009046      2B
           81009047      8E
           81009048      22
    
            short *x;      (assume data type of short is 2 bytes long)
    
          After executing a statement of "x = x+1;",
          what is the byte value pointed by x in hexidecimal?        ____________
    
          Then after "further" executing a statement of "x++;",
          what is the byte value pointed by x in hexidecimal?        ____________
    
    
        Anyone can contribute and make this fun.
    
    -sl.
5606.4CXXC::REINIGThis too shall changeWed Apr 23 1997 10:44122
From the comp.lang.c faq:  (see TURRIS::DECC note 510

2.9:    I came across some "joke" code containing the "expression"
	5["abcdef"] .  How can this be legal C?

2.11:   How do I write functions which accept 2-dimensional arrays when
	the "width" is not known at compile time?

2.13:   How can I dynamically allocate a multidimensional array?


3.1:    Why doesn't this fragment work?

		char *answer;
		printf("Type something:\n");
		gets(answer);
		printf("You typed \"%s\"\n", answer);

3.2:    I can't get strcat to work.  I tried

		char *s1 = "Hello, ";
		char *s2 = "world!";
		char *s3 = strcat(s1, s2);

based on 3.5.  What's wrong with.

	struct list *p, *base, *last;

	for(p = base; p != last; p = p->next) {
	    free(p);
	}

    Hint: There's more than thing that's wrong.

4.2.  What should the following print:

		int i = 7;
		printf("%d %d\n", i++, i++);


5.4.  Write a STR macro that stringizes it's argument.

	    #define OP plus
	    char *opname = STR(OP)

      should set opname to "plus"


5.5:    What's the difference between "char const *p" and
	"char * const p"?


5.6:    Why can't I pass a char ** to a function which expects a
	const char **?

	Come up with a example to show why it would be bad to allow
        this.  (I've seen the example several times and it always 
        takes me a long time to figure it out again.)

5.7:    My ANSI compiler complains about a mismatch when it sees

                extern int func(float);

                int func(x)
                float x;
                {...
    
        why?

5.8:    Why does the declaration

                extern f(struct x {int s;} *p);

        give me an obscure warning message about "struct x introduced in
        prototype scope"?


5.13:   What is the difference between memcpy and memmove?


9.9:    What is the size of the following structure (as reported by sizeof)

        struct S {
            int x;
            char y;
        }

        (you'll want to say something at the top of the QUIZ about
         the alignment requirements of your C compiler)

4.5:  What's the value of c?

        main(void) {
            int x = 1000000;
            int y = 1000000;
            long z = x * y;

            printf("%d\n", z);
        }

        (at the top of the quiz you'll want to state what CHAR_MIN,
          CHAR_MAX, SHORT_MIN, SHORT_MAX, INT_MIN, INT_MAX, LONG_MIN,
          LONG_MAX)

10.3  Declare a structure which contains a pointer to itself.
      Declare two structures, each of which contains a pointer to the
        other.

11.1:   Why doesn't this code:

                char c;
                while((c = getchar()) != EOF)...

        work?




        
            


5606.5What is wrong with this code?CXXC::PHILLIPSWed Apr 23 1997 14:3517
char c1=1;
char c2=2;
char c3=3;
char *cptr = &c1;
main(){
   if (*cptr++=1)
       if(*cptr++=2)
           if(!(*cptr++=5))
               printf("It worked\n");
   else
       printf("How did we get here?\n");

   printf("%d %d %d\n", c1, c2, c3);

}

5606.6quiz->think %sHANDVC::STEVELIUFri Apr 25 1997 06:517
    
    Re: .4 and .5
    
    this is really getting interesting, keep on posting ! I'll write up
    more later.
    
    -steve
5606.7CSC32::HENNINGA rose with no thornsThu May 01 1997 15:273
    Check out "The C Puzzle Book" by Alan Feuer (ISBN 0-13-115502-4).  He
    formulated the puzzles to demonstrate the ambiguity and complexity of
    the C language.  Good teaching tool!