Ask your own question, for FREE!
Mathematics 19 Online
OpenStudy (s3a):

Very simple C++ question. Basically why doesn't this work: #include int num = 5; int *numPointer = # //cout << &numPointer << endl; cout << "Hello there" << endl;

OpenStudy (anonymous):

u have to include the braces {

OpenStudy (s3a):

Netbeans has cout << "Hello there" << endl; in red underlined and it says "unexpected token cout. unable to resolve identifier cout"

OpenStudy (anonymous):

hey there's a computer science group, you may post your question there this group is only for math questions

OpenStudy (anonymous):

u have to have the curly braces and also include void main ()

OpenStudy (s3a):

Oh I see. Is there a reason why I need void main(){}?

OpenStudy (s3a):

Tomas.A: I thought I was in the computer science group. Sorry, after this question I will go there.

OpenStudy (s3a):

I mean what is the reason

OpenStudy (anonymous):

you can go straight away and i am sure agdwnwngo would help you

OpenStudy (anonymous):

void main () is the part wherein the computer understands that the program has to be executed from that place the curly brace after that is where it starts execution from till the time the curly brace ends

OpenStudy (s3a):

Ok so even in procedural programming, we use that, right?

OpenStudy (anonymous):

c++ is object orientated language

OpenStudy (s3a):

but it has c features so it can be procedural to my knowledge

OpenStudy (s3a):

i just don't know what that means in practice.

OpenStudy (anonymous):

it has some modified terms and it has to be followed

OpenStudy (anonymous):

it will be object orientated anyway but you can write code without using object (only main)

OpenStudy (s3a):

Also: #include <iostream> int void main() { int num = 5; int *numPointer = &num; //cout << &numPointer << endl; cout << "Hello there" << endl; return 0; } doesn't work: "Unable to resolve identifier cout". I am using netbeans.

OpenStudy (anonymous):

using namespace std;

OpenStudy (s3a):

but java is fully object-oriented and i can write code just using the main method. but a lot of things have to be static afterwards. is that a difference between java and c++?

OpenStudy (s3a):

i meant int main() not int void main()

OpenStudy (anonymous):

so you can do same thing in c++ too

OpenStudy (anonymous):

you can write code just using main in c++ as in java

OpenStudy (s3a):

i'm not saying you can't in C++. I'm just asking if you're forced in Java to use static and in C++ you're not.

OpenStudy (s3a):

if you code all in main and use no objects that is.

OpenStudy (anonymous):

idk im not very familiar with c++

OpenStudy (s3a):

o me neither. the real reason why i asked this question in the first place is to test the following:

OpenStudy (s3a):

#include <iostream>; using namespace std; int main() { int num = 5; // int *numPointer = &num; // Way 1 string str = &num; cout << str << endl; // Way 2 // cout << &num << endl; // cout << "Hello there" << endl; return 0; }

OpenStudy (s3a):

Way 2 works as expected but way 1 doesn't.

OpenStudy (anonymous):

ask in computer science group and u will get answer lol

OpenStudy (anonymous):

i don't know pointers

OpenStudy (s3a):

Alright, thanks still.

OpenStudy (s3a):

(I asked it there)

Can't find your answer? Make a FREE account and ask your own questions, OR help others and earn volunteer hours!

Join our real-time social learning platform and learn together with your friends!
Can't find your answer? Make a FREE account and ask your own questions, OR help others and earn volunteer hours!

Join our real-time social learning platform and learn together with your friends!