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