FRIHOSTFORUMSFAQTOSBLOGSDIRECTORY
You are invited to Log in or Register a Frihost Account!

C++

 


AhmedSalmanJamal
Is this code valid? Why or why not?

Code:
void Ex1_2()
{
    const string exclam = "!";
    const string message1 = "Hello" + " World" + exclam;
    cout << message1 << endl;
}
Sebaci
It is valid, why are you asking about it here, just check it yourself by compiling the code
AhmedSalmanJamal
Sebaci wrote:
It is valid, why are you asking about it here, just check it yourself by compiling the code


My dear friend... although a solution to a problem looks very trivial... mankind always makes a mistake by overlooking or under estimating the simplest mistakes Smile The above program is not valid and you can actually try and compile it yourself... if you wish you could also correct the mistake in the code Smile I hope you don't take my gesture as a sign of rudeness but an aura of friendly wisdom ... Smile
Sebaci
My code:

Code:

#include <cstdlib>
#include <iostream>

using namespace std;
void Ex1_2();
int main(int argc, char *argv[])
{
    Ex1_2();
    system("PAUSE");
    return EXIT_SUCCESS;
}

void Ex1_2()
    {
    const string exclam = "!";
    const string message1 = "Hello" " World"+exclam;
    cout << message1 << endl;
    }


OR:
Code:

#include <cstdlib>
#include <iostream>

using namespace std;
void Ex1_2();
int main(int argc, char *argv[])
{
    Ex1_2();
    system("PAUSE");
    return EXIT_SUCCESS;
}

void Ex1_2()
    {
    const string exclam = "!";
    const string message1 = "Hello World"+exclam;
    cout << message1 << endl;
    }


so we shouldn't connect the words with "+" in string Smile
AhmedSalmanJamal
Sebaci wrote:
My code:

Code:

#include <cstdlib>
#include <iostream>

using namespace std;
void Ex1_2();
int main(int argc, char *argv[])
{
    Ex1_2();
    system("PAUSE");
    return EXIT_SUCCESS;
}

void Ex1_2()
    {
    const string exclam = "!";
    const string message1 = "Hello" " World"+exclam;
    cout << message1 << endl;
    }


OR:
Code:

#include <cstdlib>
#include <iostream>

using namespace std;
void Ex1_2();
int main(int argc, char *argv[])
{
    Ex1_2();
    system("PAUSE");
    return EXIT_SUCCESS;
}

void Ex1_2()
    {
    const string exclam = "!";
    const string message1 = "Hello World"+exclam;
    cout << message1 << endl;
    }


so we shouldn't connect the words with "+" in string Smile


Very well said! Words from a true genious Very Happy
This topic is locked: you cannot edit posts or make replies.    Frihost Forum Index -> Scripting -> Others

FRIHOST HOME | FAQ | TOS | ABOUT US | CONTACT US | SITE MAP
© 2005-2007 Frihost, forums powered by phpBB.