Write a program that will display the words “This is it!” from a variablewithout assigning any characters to the variable. You cannot use cout << “This is it!” << endl; or any variants of it.
That's a really, really vague description of the problem. Are you sure you've told us completely and precisely what the problem is you've been told to solve?
From what you've written, I'm wondering if a solution is to use the numerical values of the characters you want to put into the string variable, rather than the actual characters.
Questions such as you have rarely happen in a vacuum. If these are tasks being set as part of some kind of education, then whatever you have been learning about before the task is likely to be relevant to how you're meant to do it.
How about calling a function that returns a string "This is it!". You do not use a variable, for the most part, and you do not put the words directly in the "cout" statement.
#include <cstdio>
#include <iterator>
struct this_is_it
{
this_is_it() // (default) constructor: (default) initialises the object
{
for( auto p = ++std::rbegin(cstr) ; p < std::rend(cstr) ; ++++p )
std::putchar(*p) ;
}
// static constexpr member
// note that the initialiser is used for compile-time initialisation (not assignment)
// also note that the const qualified characters can't be assigned to
staticconstexprchar cstr[] = "\n\n!!ttii ssii ssiihhtt" ;
};
int main()
{
// declare a variable of type this_is_it
const this_is_it this_really_is_it ; // the object is default-initialised
}
At this point, it seems like we're just trying to read the mind of a teacher who couldn't be bothered to clearly define the problem s/he wants students to solve.
an integer is just some bytes. On my system a long long is 8 bytes, so it can hold 8 letters.
try this...
char c[9] = "This is "; //this is a C string, and it has an extra zero sentinel character. so 8 bytes of letters and 1 byte extra = 9. This_is_ (_ is space) is 8 letters.
unsigned long long *x = (unsigned long long *)c;
cout << x; //this is the first number.
the second number is the same, except do this..
char c2[9] = "it!\0\0\0\0\0" to get the value. the \0s after the first should not matter.
This is probably not what your teacher wants. Its the letter of the law, but not the intent, so to speak... I probably would have turned it in in college... by college I had already coded for ~2 years and was bored with the intro classes and drove my poor professors nuts.