• Log in or sign up for an account here: https://www.sythe.org/login

Fun exam questions

Joined
Apr 21, 2005
Sythe Gold
5,470
Messages
8,074
Discord Unique ID
742989175824842802
Discord Username
Sythe
Supporting Business
Discord Voice
Poképedia
Who did this to my freakin' car!
Dat Boi
Dolan Duck
Dolan Trump
I'm LAAAAAAAME
Live Free or Die
Mew
Mewtwo
PHP Shit Show 2k26
Poké Prizebox
Rust Player
Sythe Awards 2016 Winner
Sythe Awards 2017 Winner
Sythe Awards 2019 Winner
Tier 3 Prizebox
Toast Wallet User
Some of you may know I've been a C programming tutor for a few years.

If you're taking a C programming course at university these are some of the harder types of questions you might find on a final exam:

Q1: Is the following valid C?
#include<stdio.h>

int main() {
int (*main)(); {
printf("hello world\n");

return 0;
​
}
​
}
Q2: How many times does the following code print "hello\n"?
#include <stdio.h>
#define _(x) (;; )

int main() {
for _(int i = 0; i < 100; i++) {
printf("hello\n");
​
}
​
return 0;
​
}
Q3: What does the following code do?
int main(void);int(*__)()=main;int(**_)()=&__;int main(void){(*_)();}
Q4: Why is the following a bad idea?
while(1) fork();
Q5: What would the following code do?
if (*'z' = 010); {
printf("%d", *'z');
​
}
Q6: What is the following code equivalent to?
char a[10];
int b = 5;
*(a + b) = 5;
Q7: What is the type of foo in the following? Is it valid C?
typedef void *(*a)(void);
a (*(*foo)(void))(void);
Q8: what is the return value of this function?
int function(void) {
return ({024;007;006;004;001;011});
​
}
Q9: What is the value of c after the following code is executed (assuming c is 2 before execution)?:
c += c++++c;
 
Wow, these could definitly be helpful, ive been starting programming and was planning on taking some courses. Thanks for the cheat. :P
 
4) looks like a fork bomb.
5) will print 10? EDIT: 8, it assigned the 010 as an octal number?

It must take a long time to know enough C to answer ones like Q9 in an exam hall :o
 
Supporting Business
Discord Voice
Poképedia
Who did this to my freakin' car!
Dat Boi
Dolan Duck
Dolan Trump
I'm LAAAAAAAME
Live Free or Die
Mew
Mewtwo
PHP Shit Show 2k26
Poké Prizebox
Rust Player
Sythe Awards 2016 Winner
Sythe Awards 2017 Winner
Sythe Awards 2019 Winner
Tier 3 Prizebox
Toast Wallet User
4) looks like a fork bomb.
5) will print 10? EDIT: 8, it assigned the 010 as an octal number?

Correct, it is deferencing the address 'z' (the asciicode of z) and assigning it the value '010', which is octal for 8. The branch would always be taken because it is an assignment and an not equality operator; But in this case the if-statement is followed immediately by a semicolon, so the following statement is not part of any branch -- it is instead an independent code-block.

It must take a long time to know enough C to answer ones like Q9 in an exam hall :o
You should take in an order of precedence table of operators if you are allowed. This might help you solve a question like 9.

In this particular case I believe the language states the code is ambiguous and undefined.

One might interpret it as:
c += (c++) + (+c); // or
c += (c) + (+(++c));
 
1: No

2: 99 times because it's not stated as less than or equal too. ( Also if it would've been a while loop, and the increment sign was in front of the output of the integer! )

3: Not valid

4: Not valid

5: If z is a pointer to 010

6: 0? A is a char with an integer, you couldn't compile

7: Yes

8: Idk

9: C

Idk if all of these are right, those were pretty tricky.
 
Supporting Business
Discord Voice
Poképedia
Who did this to my freakin' car!
Dat Boi
Dolan Duck
Dolan Trump
I'm LAAAAAAAME
Live Free or Die
Mew
Mewtwo
PHP Shit Show 2k26
Poké Prizebox
Rust Player
Sythe Awards 2016 Winner
Sythe Awards 2017 Winner
Sythe Awards 2019 Winner
Tier 3 Prizebox
Toast Wallet User
Wrong.

2: 99 times because it's not stated as less than or equal too. ( Also if it would've been a while loop, and the increment sign was in front of the output of the integer! )
Wrong. Look up #define macros.

3: Not valid
Wrong.

4: Not valid
Wrong.

5: If z is a pointer to 010
Wrong/Didn't answer the question.

6: 0? A is a char with an integer, you couldn't compile
Wrong.

Wrong/Didn't answer the question.

Wrong.

Wrong.

You scored: 0/9.
 
Le Monkey
PHP Shit Show 2k26
Potamus
Prove it!
Sythe Awards 2011 Winner
Tier 1 Prizebox
Tortoise Penis
Trole
UWotM8?
Wait, do you not have an Archer rank?
(I promise I didn't look at the other posts in this thread)


1. Yes.
2. Infinite: you have a for(;;) with that macro.
3. I don't know.
4. It would eventually use up all the resources on your system because fork() spawns a new copy of the running executable, right?
5. You have a semicolon after your if statement, so, um, the code block after it doesn't depend on that? Not to mention it's a single = sign not ==, so the if statement has no real test expression anyway. In the off-chance that you did this intentionally, I don't know what it's supposed to do.
6. I give up.
7. Function of type **void.
8. Nothing, because those should be commas, not semicolons. EDIT: VS2008 doesn't compile that.
9. c += c++ +(+c) = 2 += 2 + 2 = 6? I thought it was 7 at first but then I realized that if it was (c++) (++c) there would be no mathematical operation.
 
Supporting Business
Discord Voice
Poképedia
Who did this to my freakin' car!
Dat Boi
Dolan Duck
Dolan Trump
I'm LAAAAAAAME
Live Free or Die
Mew
Mewtwo
PHP Shit Show 2k26
Poké Prizebox
Rust Player
Sythe Awards 2016 Winner
Sythe Awards 2017 Winner
Sythe Awards 2019 Winner
Tier 3 Prizebox
Toast Wallet User
(I promise I didn't look at the other posts in this thread)
1. Yes.
Correct.
2. Infinite: you have a for(;;) with that macro.
Correct.
3. I don't know.

Wrong/Didn't answer.

int main(void); //Prototype for main
int(*__)()=main; // Function pointer called __ which points at main
int(**_)()=&__; // Function pointer pointer called _ which points at __
int main(void){
(*_)(); // dereference _, and call the resulting function pointer. (Infinite recursion.)
}

4. It would eventually use up all the resources on your system because fork() spawns a new copy of the running executable, right?

Correct, fork bomb.

5. You have a semicolon after your if statement, so, um, the code block after it doesn't depend on that? Not to mention it's a single = sign not ==, so the if statement has no real test expression anyway. In the off-chance that you did this intentionally, I don't know what it's supposed to do.

Half mark, didn't answer the question but got halfway there.

(It is intentional, and it's good you picked it up.)

The code dereferences the ascii-code for 'z' and sets the memory there to octal 010. (decimal 8). It then proceeds to the unconnected codeblock, and prints the memory at the address which is the ascii-code of 'z', which we just set to 010, which is 8. So it prints 8.

6. I give up.
Wrong/didn't answer the question.

The code is equivalent to the following:
char a[10];
int b = 5;
a = 5;

or

char a[10];
a[5] = 5;


7. Function of type **void.
Wrong, it's a function pointer. I won't reveal what type of function pointer.

8. Nothing, because those should be commas, not semicolons. EDIT: VS2008 doesn't compile that.

Wrong.

The last value or variable in a code-block is it's value if used in an expression. This is actually valid C but not all compilers support it. That function returns the octal value 011.

9. c += c++ +(+c) = 2 += 2 + 2 = 6? I thought it was 7 at first but then I realized that if it was (c++) (++c) there would be no mathematical operation.

It's ambiguous, it depends on the compiler. I'll give you this mark.

Your score: 4.5/9.
 
Le Monkey
PHP Shit Show 2k26
Potamus
Prove it!
Sythe Awards 2011 Winner
Tier 1 Prizebox
Tortoise Penis
Trole
UWotM8?
Wait, do you not have an Archer rank?
char a[10];
int b = 5;
a = 5;

or

char a[10];
a[5] = 5;

I can't believe I didn't see that one right away. Oh well...
 
Thankyou! Im currently doing computer programming, year 12 and was looking as of what university exams would look like. One quick question, do you think by the time im in university they will still teach c? or just c++ and other?
 
Supporting Business
Discord Voice
Poképedia
Who did this to my freakin' car!
Dat Boi
Dolan Duck
Dolan Trump
I'm LAAAAAAAME
Live Free or Die
Mew
Mewtwo
PHP Shit Show 2k26
Poké Prizebox
Rust Player
Sythe Awards 2016 Winner
Sythe Awards 2017 Winner
Sythe Awards 2019 Winner
Tier 3 Prizebox
Toast Wallet User
Thankyou! Im currently doing computer programming, year 12 and was looking as of what university exams would look like. One quick question, do you think by the time im in university they will still teach c? or just c++ and other?


Any respectable computer science or IT degree will contain at minimum one course in each C and Java programming. You might also get your hands on C++ depending on how good the university is.
 
This looks very difficult not even sure if i wanna major in computer science anymore :/

Don't let the syntax scare you off. Once you start learning the language and start understanding the basics and getting into the harder stuff, this will be nothing.
 
duelarena.gg
Back
Top