C programming language quiz

This is a discussion on C programming language quiz within the C Programming forums, part of the General Programming Boards category; Hello everybody, I am learning C language and I would like to make some quiz to test my progress. I ...

  1. #1
    Registered User
    Join Date
    Apr 2002
    Posts
    6

    Question C programming language quiz

    Hello everybody,

    I am learning C language and I would like to make some quiz to test my progress. I have taken the test on BrainB and TechniProfiles site but they have little question. Who know another link that have the good quiz, please help me.

    Thanks for your kindness.
    Trancongan.

  2. #2
    Registered User Nutshell's Avatar
    Join Date
    Jan 2002
    Posts
    1,020
    Is this correct?
    Code:
    while ( p != NULL ) {
       free( p );
       p = p->next
    }
    Which one is correct:
    Code:
    char *p
    
    strcpy( p, "hellow world." );
    or
    Code:
    char *p = "hello";

  3. #3
    Code Goddess Prelude's Avatar
    Join Date
    Sep 2001
    Posts
    9,796
    Prelude's semi-difficult quiz for people wanting more than hello world questions.
    ---------------------------------------------------

    1) How many ways according to the C standard can main be defined?

    2) What will the following code print?
    Code:
    char *p = "World";
    printf ( "%*c%p %p!\n", 18, ' ', "Hello, ", p );
    3) What does the following declaration mean?
    typedef struct foo { int foo; } foo;

    4) (True or False): An int is 4 bytes.
    4b) An int is 4 times the size of a char.

    5) (True or False): a[x] = ++x; is valid.
    5b) is safe.

    6) What is wrong with the following code:
    Code:
    struct s { int foo; } one = {1}, two = {2};
    one.foo ^= two.foo ^= one.foo ^= two.foo;
    printf ( "%d %d\n", one, two );
    7) (True or False): Mergesort partitions a file and then recursively sorts each part.

    8) Is the following code valid C?
    Code:
    #include <stdio.h>
    
    int main ( void )
    {
      int i;int i = 5;int i;
      printf ("%d\n", i );
      return 0;
    }
    9) What will the following code print:
    Code:
    char *p = malloc ( 20 * sizeof *p );
    printf ( "%u\n", sizeof p );
    9b) What if the printf were changed to
    printf ( "%d\n", sizeof *p );

    10) Assuming a is a working array, is the following code valid?
    1[a] = 1;

    Please don't run the programs or test the code, this is a quiz on your knowledge of C, not running test programs.

    -Prelude
    Last edited by Prelude; 04-19-2002 at 10:22 PM.
    My best code is written with the delete key.

  4. #4
    Registered User stautze's Avatar
    Join Date
    Apr 2002
    Posts
    195
    Originally posted by Nutshell
    Is this correct?
    Code:
    while ( p != NULL ) {
       free( p );
       p = p->next
    }
    .no . you could assign p then free, but its pointless.
    Which one is correct:
    Code:
    char *p
    
    strcpy( p, "hellow world." );
    or
    Code:
    char *p = "hello";
    I'm going with the second. The first is is going to get you a pointer intialized to the more-or-less random contents of the stack location
    Last edited by stautze; 04-21-2002 at 04:56 AM.

  5. #5
    Registered User stautze's Avatar
    Join Date
    Apr 2002
    Posts
    195
    1) I'm thinking int main(void), int main(), and
    int main(declarations).

    2) I'm not sure.. can, is *p a generic *s?

    3) it is the equivalent of int struct;

    4)
    a) false (maybe on an ancient RISC arch)
    b) false

    5)
    a) I don't think so.
    b) I hope not.

    6) It is completly screwed up. you missed the semicolon after the struct, and your calling it members all wrong.

    7) False, you never said anything about merging the sorted sublist into a single sorted list at the end. Oh yea the partitions are equal unlike quicksort and if my memory is serves me, your looking at O(nlog(n)).

    8) No you can't redeclare.

    9) Can you even do that??

    10) I'm just guessing... yes.

  6. #6
    Registered User C_Coder's Avatar
    Join Date
    Oct 2001
    Posts
    523
    Have you tried the 1 on this site?
    http://www.cprogramming.com/cgi-bin/quiz.cgi
    All spelling mistakes, syntatical errors and stupid comments are intentional.

  7. #7
    ¡Amo fútbol!
    Join Date
    Dec 2001
    Posts
    2,136
    Can't be seen as wrong.
    Last edited by golfinguy4; 04-21-2002 at 02:09 PM.

  8. #8
    Code Goddess Prelude's Avatar
    Join Date
    Sep 2001
    Posts
    9,796
    >The first is is going to get you a pointer intialized to the more-or-
    >less random contents of the stack location
    Actually, it should result in a run-time error because you are assigning to memory that you don't own.

    1) I'm thinking int main(void), int main(), and
    int main(declarations).
    Three. int main ( void ), int main ( int argc, char **argv ), int main ( int argc, char *argv[] ). Those three are stated explicitly but it does say that any names for argc and argv can be used.

    2) I'm not sure.. can, is *p a generic *s?
    It will print 18 spaces, an address, a space, and then another address.

    3) it is the equivalent of int struct;
    Could you elaborate?

    4)
    a) false (maybe on an ancient RISC arch)
    b) false
    The actual sizes of integers will vary from system to system, so both are false.

    5)
    a) I don't think so.
    b) I hope not.
    It is valid, but is most definitely not safe. Though quite a few compilers will flag a warning, I don't think any will halt compilation.

    6) It is completly screwed up. you missed the semicolon after the struct, and your calling it members all wrong.
    I didn't miss the semicolon, it was placed after declaring and initializing the instances. The printf may or may not work, and the swap operation is absolutely hideous. The swap is also undefined, care to guess why?

    7) False, you never said anything about merging the sorted sublist into a single sorted list at the end. Oh yea the partitions are equal unlike quicksort and if my memory is serves me, your looking at O(nlog(n)).
    Correct, I was describing Quicksort, not Mergesort.

    8) No you can't redeclare.
    Nope, it's completely valid as long as only one of the variables is initialized. If any more are initialized then it constitutes a redeclaration and the compiler will flag an error. But as is that code will compile and work.

    9) Can you even do that??
    Absolutely, it won't give you the results you want, but it will most certainly work. The first print will result in the size of a single pointer and the second will result in the size of a single char.

    10) I'm just guessing... yes.
    Good guess, if you break down array notation to pointer notation you have *( 1 + a ) = 1, which is perfectly valid.

    -Prelude
    My best code is written with the delete key.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. What language did they make Java in?
    By jverkoey in forum A Brief History of Cprogramming.com
    Replies: 17
    Last Post: 07-03-2005, 05:18 PM
  2. Strange loop
    By D@rk_force in forum C++ Programming
    Replies: 22
    Last Post: 12-18-2004, 02:40 PM
  3. assembly language...the best tool for game programming?
    By silk.odyssey in forum Game Programming
    Replies: 50
    Last Post: 06-22-2004, 02:11 PM
  4. Language of choice after C++
    By gandalf_bar in forum A Brief History of Cprogramming.com
    Replies: 47
    Last Post: 06-15-2004, 02:20 AM
  5. Languages dying
    By Zewu in forum A Brief History of Cprogramming.com
    Replies: 31
    Last Post: 07-29-2003, 11:08 AM

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21