Random Test =D

Posts 1–13 of 13 · Page 1 of 1
Random Test =D
I've been reading through a book, and so far I've started to skim the surface of C++.
I decided to start keeping a few notes, so I could refer back to them, and in return, I would answer them.

Almost like Cornell Notes. Anyways, I wanted to post the questions and answers on here:
1.) So the people who actually know, can check if they're right
2.) SO people who don't know, can see if they know the answers

I'll post the questions at the top, and the answers I got, at the bottom.

I figure this might be a lil' fun, and a change from all the help topics x)

Questions:

1.) What is used compile .cpp files using the Visual Studio Command Prompt?:
2.) How do you start a function?: (Not sure if you would call it a source, or what you would call it, but I understand what I mean xP )
3.) How do you end a function?:
4.) How would you use the header iostream?:
5.) How would you declare the variable 'length'?:
6.) How do you declare more than one variable without starting a new line?:
7.) What does cout stand for?:
8.) What does cin stand for?:
9.) What is the << operator, and what does it do?:
10.) What is the >> operator, and what does it do?:

|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
Answers:
1.) C:\...>cl -GX Sample.cpp
2.) int main()
3.) return 0;
4.) #include <iostream>
5.) int length;
6.) int length, width;
7.) Console Output(Mainly writing something on the computer screen)
8.) Console Input(linked to the keyboard by default, can be linked to other input sources)
9.) << is the output operator, it processes inputted data and gives an output
10.) >> is the input operator, it inputs data into the program to be processed


If my answers are wrong, please lemme know x)
<< and >> are also bitwise operators(shift left and shift right), look those up on google if you want to know more about em ^^
Quote Originally Posted by Hell_Demon View Post
<< and >> are also bitwise operators(shift left and shift right), look those up on google if you want to know more about em ^^
Hopefully it shows it later on on this book x)
oh really nice to see that you are not going super fast and actually trying to get something on your head :P seriously keep going.
For number 2/3 it would be a function not really a source.(I could have misinterpreted what you mean though)
Quote Originally Posted by Crash View Post
For number 2/3 it would be a function not really a source.(I could have misinterpreted what you mean though)
Thanks x) I'll change it
Quote Originally Posted by Alroundeath View Post


Thanks x) I'll change it
what he said is not that right.. you are going to get confused, because main isnt just a function... and it doesnt need to be int main(), it can be void main(), and you dont need to return 0 on a funcion you can return almost anything.

Code:
double getResult(double num1, double num2)
{
     return num1 + num2;
}
this is a function and as you can see... not nearly the same as int main() and return 0...

edit: just keep reading your book and you will understand, don't try to understand that yet and dont get confused
Quote Originally Posted by 'Bruno View Post
what he said is not that right.. you are going to get confused, because main isnt just a function... and it doesnt need to be int main(), it can be void main(), and you dont need to return 0 on a funcion you can return almost anything.

Code:
double getResult(double num1, double num2)
{
     return num1 + num2;
}
this is a function and as you can see... not nearly the same as int main() and return 0...

edit: just keep reading your book and you will understand, don't try to understand that yet and dont get confused

o.o.................. /

Currently looking at control statements.

After I finish this chapter, I'll note everything in the chapter and add it to this thread x)
Quote Originally Posted by Alroundeath View Post



o.o.................. /

Currently looking at control statements.

After I finish this chapter, I'll note everything in the chapter and add it to this thread x)
just "forget" it... and go on good luck
I'm kinda a noob at C++, so don't flame me too hard, but I thought that the "return" statement was to return a value to be used later on?

Like If you had this:

Code:
int main(int num1 = 54)
{
return num1;
}

int main2()
{
cout << main << endl;
return 0;
}
It would show "54" in the console...
Quote Originally Posted by Lolland View Post
I'm kinda a noob at C++, so don't flame me too hard, but I thought that the "return" statement was to return a value to be used later on?

Like If you had this:

Code:
int main(int num1 = 54)
{
return num1;
}

int main2()
{
cout << main << endl;
return 0;
}
It would show "54" in the console...
yes and no... because as soon as main() ends, the program ends. And also from what i remember you cant attribute num1 with 54 at the function param.

but yes you return a value to be used later, but not with main(), return 0 means that the program exited without problems (i think), and to actually end the program.

but if you use:

Code:
int getNum()
{
    return 1337;
}

int main()
{
    int num = getNum();
    cout << num << endl;
    return 0;
}
that yes, its valid

Output:

Code:
1337
Quote Originally Posted by Lolland View Post
I'm kinda a noob at C++, so don't flame me too hard, but I thought that the "return" statement was to return a value to be used later on?

Like If you had this:

Code:
int main(int num1 = 54)
{
return num1;
}

int main2()
{
cout << main << endl;
return 0;
}
It would show "54" in the console...
So far what I've learned is that 0 is false, and 1 is true. So the return is false, so it would not
return. This is just a guess, but if the statement was return 1; it would return and enter 54 in
the console.

I'll check that right quick.

Edit: I read earlier in the book, and there's different codes for the exiting of the program

return 0; means the program exited successfully and without any errors.

Quote Originally Posted by Alroundeath View Post


return 0; means the program exited successfully and without any errors.

just like i said in the post before yours
Posts 1–13 of 13 · Page 1 of 1

Post a Reply

Similar Threads

Tags for this Thread

None

Talk with us