5
1
I am back with a brand new puzzle for C/C++ addicts. Following the feedback received on the 1st puzzle, this time I will try to make the requirements crystal clear and to provide a perfectly valid code.
Here is the problem. Given the following code:
#include <iostream>
char message[6]="hello";
void print_hello_message() {
std::cout << message;
}
int main() {
char* q = &message[0];
// insert your code here
}
You are required to insert two more lines where the comment specifies in order to make the program print "hello" and nothing more, with the following restrictions:
- the first line will NOT call any function, including cout
- the second line will contain AT MOST 5 letters (and as many other symbols as you want)
- the first line may contain new variable declarations but may not initialize them
- the symbols # and / will not be used at all.
no logical operators will be used
The shortest code wins!
Does
cout
count as a function call ? – Paul R – 2012-09-29T21:12:07.747Yes of course. To make it clear I'll edit now and specify. Thanks for asking. – Bogdan Alexandru – 2012-09-29T21:23:42.467
A tip for the next quiz: Please only allow standard portable C++ code. The workaround with function pointers is implementation defined on whether it actually works or not. – Xeo – 2012-09-30T09:48:16.883
But
cout
isn't a function call.<<
is a function call, when applied tocout
. – celtschk – 2014-06-21T08:08:08.110