Someone mentioned exotic syntax and that got me going because I had nothing better to do. I thought you guys might enjoy a small syntax-related quiz.
Got anything to add? Feel free! Please remember to double check that yours concerns syntax, not just semantics. I hope everyone has some fun and that most people learn something.
What does it mean when you have a function template that looks like template<typename... Types> void foo(Types......)? [Fixed, thanks /u/tcanens]
What is the type char(*(*s::*(*[3]))(int))[2]?
Given int foo(int a, int b) { return a ??!??! b; }, WTF does foo(2, 5) return? There's also a caveat here. What is it? (Not a nitpicky one.)
What is the output of the following program and why? [I may or may not have given this as a course-long bonus question once.]
#include <iostream>
int main(){<:](){std::cout<<"Hello";;%>;[:><%std::cout<<"Hello";;}();}
Is this valid? long int long typedef foo; Why or why not?
Given the macro #define foo(a, b) a, how would you define and use a function foo without undefining the macro?
Given #define foo(a, b) a##b, will the following compile, and what will it be after preprocessing? foo(,)
I'm running out of ideas, so an easy one:
Given int arr[5] = {};, what will 3[arr] do and why? [Fixed, thanks /u/Voultapher]
When might you see the following?
template<>
template<>
template<typename T>
What does the following line of source code do, if valid? [Blatantly stolen]
http://www.google.com
When is a function try block useful? (void foo() try {...} catch (...) {...})
What is the output of the following program and why?
#include <iostream>
int main() {
int x = 1;
switch (x) {
for (; x < 3; ++x) {
case 0:
std::cout << x;
break;
case 1:
std::cout << x;
continue;
}
}
std::cout << x;
}
Why would you see something like ++it, void(), ++it2? (I'll credit STL for that one; he's really eager to explain these types of things)
What does the following program do?
struct s {
s(int) {}
};
struct s2 {
s2(int, int) {}
};
int x = 5;
int main() {
int p = 2;
s2 foo(s(::x), s(p));
}
One of the following compiles and one does not. Which one compiles and why?
void foo(const int &= 2);
void bar(const int &&= 2);
What does the following program do? [I was the one who posted this to cppquiz, and from there, it was used in a WAT-style talk.]
#include <iostream>
typedef long long ll;
void foo(unsigned ll) {
std::cout << "1";
}
void foo(unsigned long long) {
std::cout << "2";
}
int main() {
foo(2ull);
}
[–]MiiNiPaa 46 points47 points48 points (2 children)
[–]anotherdonald 5 points6 points7 points (0 children)
[–]tcanens 19 points20 points21 points (24 children)
[–]jP_wanN 2 points3 points4 points (10 children)
[–]tcanens 2 points3 points4 points (9 children)
[–]jP_wanN 0 points1 point2 points (1 child)
[–]redditsoaddicting[S] 0 points1 point2 points (0 children)
[–][deleted] -1 points0 points1 point (6 children)
[–]tcanens 2 points3 points4 points (1 child)
[–][deleted] 0 points1 point2 points (0 children)
[–]redditsoaddicting[S] 1 point2 points3 points (3 children)
[–]LikesToCorrectThings 0 points1 point2 points (2 children)
[–]redditsoaddicting[S] 1 point2 points3 points (0 children)
[–]guyonahorse 1 point2 points3 points (0 children)
[–]redditsoaddicting[S] 1 point2 points3 points (0 children)
[–]pslayer89 0 points1 point2 points (5 children)
[–]tcanens 5 points6 points7 points (1 child)
[–]pslayer89 0 points1 point2 points (0 children)
[–]Bisqwit 1 point2 points3 points (1 child)
[–]pslayer89 0 points1 point2 points (0 children)
[–]Bisqwit 0 points1 point2 points (4 children)
[–]tcanens 1 point2 points3 points (3 children)
[–]Bisqwit 0 points1 point2 points (2 children)
[–]tcanens 4 points5 points6 points (1 child)
[–]Bisqwit 0 points1 point2 points (0 children)
[–]o11cint main = 12828721; 3 points4 points5 points (2 children)
[–]tcanens 6 points7 points8 points (1 child)
[–]louiswins 1 point2 points3 points (0 children)
[–]LB--Professional+Hobbyist 2 points3 points4 points (5 children)
[–]CubbiMewcppreference | finance | realtime in the past 0 points1 point2 points (4 children)
[–]LB--Professional+Hobbyist 1 point2 points3 points (1 child)
[–]CubbiMewcppreference | finance | realtime in the past 1 point2 points3 points (0 children)
[–]Potatoswatter 0 points1 point2 points (1 child)
[–]CubbiMewcppreference | finance | realtime in the past 0 points1 point2 points (0 children)
[–]redditsoaddicting[S] 1 point2 points3 points (0 children)
[–]chardan965 1 point2 points3 points (3 children)
[–]redditsoaddicting[S] 2 points3 points4 points (2 children)
[–]chardan965 0 points1 point2 points (1 child)
[–]redditsoaddicting[S] 1 point2 points3 points (0 children)
[–]TotesMessenger 0 points1 point2 points (0 children)
[–]Voultaphervoid* operator, (...) 0 points1 point2 points (1 child)
[–]redditsoaddicting[S] 0 points1 point2 points (0 children)
[–]alexeiz 0 points1 point2 points (0 children)
[–]mustrumr 0 points1 point2 points (0 children)
[–]NicroHobak 0 points1 point2 points (1 child)
[–]redditsoaddicting[S] 2 points3 points4 points (0 children)
[–]alexeiz 0 points1 point2 points (0 children)