| | |
Why does the following code works?
Please support our C++ advertiser: Intel Parallel Studio Home
![]() |
•
•
Join Date: Nov 2009
Posts: 2
Reputation:
Solved Threads: 0
The following code works, it prints hello world.
Also, depending on the second value, it either gives segmentation fault or doesn't gives segmentation fault.
Can someone please explain me what is happening internally.
Also, depending on the second value, it either gives segmentation fault or doesn't gives segmentation fault.
Can someone please explain me what is happening internally.
C++ Syntax (Toggle Plain Text)
int main = ( cout << "Hello world!\n", 195 );
0
#2 34 Days Ago
I am really not sure what is going on here. You are attempting to use a main() function like I've never seen it before. Therefore, this method you are using is more than likely unconventional.
To me, it seems like you are declaring an 'int' type variable called main (which I think is a c++ reserved keyword) and then attempting to initialize the poor int var with a bunch of non-int related gobbledygook.
I am not sure if you are trying to inline the main() function, or attempting to pass in a couple of arguments to the main() function (in which case you could consider using the argc argv[] command-line arguments) or if you are just trying to use a couple of default arguments (which I'm not sure if it is allowed for main()).
Anyway, the rest of the world is coding main() like this:
To me, it seems like you are declaring an 'int' type variable called main (which I think is a c++ reserved keyword) and then attempting to initialize the poor int var with a bunch of non-int related gobbledygook.
I am not sure if you are trying to inline the main() function, or attempting to pass in a couple of arguments to the main() function (in which case you could consider using the argc argv[] command-line arguments) or if you are just trying to use a couple of default arguments (which I'm not sure if it is allowed for main()).
Anyway, the rest of the world is coding main() like this:
C++ Syntax (Toggle Plain Text)
#include<iostream> using namespace std; int main() { cout << "Hello world!\n"; cin.get(); return 0; }
0
#4 34 Days Ago
I am lost as well.. without the assignment operator, it would make more sense because it would appear to use a constructor to initialize the main() object, just like one could initialize variable like this:
C++ Syntax (Toggle Plain Text)
int x(10), y(20);
![]() |
Similar Threads
- PHP MySQL Code Works But Still Fills Error Logs with one error (PHP)
- Please advice how the follwoing code works (PHP)
- Integer partition: code works - any suggestion to improve it? (C++)
- Code works with Mozilla, but not with other browsers... (PHP)
- How this code works??? (C)
- Short code - it works on VC++ Express but not on Bloodshed!! (C++)
- ASP Code Works on Local 127.0.0.1 but Not on ISP's Server (ASP)
Other Threads in the C++ Forum
- Previous Thread: Using Graphics Pointer to Draw objects(TREE) in a Class (Windows Forms Applications)
- Next Thread: Creating an xy screen of tiny boxes
| Thread Tools | Search this Thread |
api application array arrays based beginner binary bmp c++ c/c++ calculator char char* class classes code coding compile compiler console conversion convert count data database delete deploy developer dll download dynamiccharacterarray email encryption error file format forms fstream function functions game generator givemetehcodez graph gui homeworkhelp iamthwee ifstream image input int java lib library list loop looping loops map math matrix memory multiple newbie news number numbertoword output pointer problem program programming project python random read recursion recursive reference rpg simple sorting string strings temperature template text text-file tree url variable vector video visual visualstudio win32 windows winsock wordfrequency wxwidgets





