Explore BrainMass

Explore BrainMass

    How to declare or use Variables in C++ ?

    This content was COPIED from BrainMass.com - View the original, and get the already-completed solution here!

    Which of the following variable declarations are correct? If a variable declaration is not correct give the reason(s) and provide the correct variable declaration.

    n = 12; //Line 1
    char letter = ; //Line 2
    int one = 5, two; //Line 3
    double x, y, z; //Line 4

    Line 3 and 4 are correct but what is wrong with Line 1 and Line 2?

    © BrainMass Inc. brainmass.com March 4, 2021, 6:09 pm ad1c9bdddf

    Solution Preview

    n = 12 //Line 1
    * Undefined Symbol n
    Remedy: declare it as an integer.
    int n = 12;

    char letter = ; //Line ...

    Solution Summary

    The solution is comprised of examples which shows some common mistakes in variable declaration and definition.