<< and >> are also bitwise operators(shift left and shift right), look those up on google if you want to know more about em ^^
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)
Last edited by Alroundeath; 06-30-2010 at 05:33 AM.
<< and >> are also bitwise operators(shift left and shift right), look those up on google if you want to know more about em ^^
Ah we-a blaze the fyah, make it bun dem!
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.
Light travels faster than sound. That's why most people seem bright until you hear them speak.
Alroundeath (06-30-2010)
For number 2/3 it would be a function not really a source.(I could have misinterpreted what you mean though)
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.
this is a function and as you can see... not nearly the same as int main() and return 0...Code:double getResult(double num1, double num2) { return num1 + num2; }
edit: just keep reading your book and you will understand, don't try to understand that yet and dont get confused
Last edited by 'Bruno; 06-30-2010 at 05:39 AM.
Light travels faster than sound. That's why most people seem bright until you hear them speak.
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:
It would show "54" in the console...Code:int main(int num1 = 54) { return num1; } int main2() { cout << main << endl; return 0; }
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:
that yes, its validCode:int getNum() { return 1337; } int main() { int num = getNum(); cout << num << endl; return 0; }
Output:
Code:1337
Light travels faster than sound. That's why most people seem bright until you hear them speak.
Hell_Demon (06-30-2010)
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.
Last edited by Alroundeath; 06-30-2010 at 06:31 AM.