•
•
•
•
What is DaniWeb IT Discussion Community?
You're currently browsing the C section within the Software Development category of DaniWeb, a massive community of 402,922 software developers, web developers, Internet marketers, and tech gurus who are all enthusiastic about making contacts, networking, and learning from each other. In fact, there are 2,997 IT professionals currently interacting right now! Registration is free, only takes a minute and lets you enjoy all of the interactive features of the site.
Please support our C advertiser: Programming Forums
Views: 2605 | Replies: 21
![]() |
Oh, is this the "hello world without a semicolon" problem with a C++ twist?
#include <iostream>
int main()
{
if ( std::cout<<"Hello, world!"<<std::endl ) {
}
} I'm a programmer. My attitude starts with arrogance, holds steady at condescension, and ends with hostility. Get used to it.
>Nothing was returned
Standard C++ returns 0 by default. Returning from main can be tricky, especially if you switch languages and work with legacy code a lot. In pre-standard C++ you need to explicitly return a value. In C89 you need to explicitly return a value. In standard C++ and C99, you can omit the return value and 0 will be returned automagically.
However, because C99 isn't widely implemented yet, everyone follows the intersection of C89 and C99 to avoid nonportable code during the interrim of changing from old standard to new standard. Since standard C++ is well implemented now, it's safe to omit the return value, but many still do it explicitly anyway as a matter of style and consistency.
My preference is to omit the return value unless I return failure, then I return success explicitly as well:
>don't you have to put something inside the braces?
No, an empty block is legal. It's roughly equivalent to:
But that uses a semicolon, so it's not a valid solution for the problem.
Standard C++ returns 0 by default. Returning from main can be tricky, especially if you switch languages and work with legacy code a lot. In pre-standard C++ you need to explicitly return a value. In C89 you need to explicitly return a value. In standard C++ and C99, you can omit the return value and 0 will be returned automagically.
However, because C99 isn't widely implemented yet, everyone follows the intersection of C89 and C99 to avoid nonportable code during the interrim of changing from old standard to new standard. Since standard C++ is well implemented now, it's safe to omit the return value, but many still do it explicitly anyway as a matter of style and consistency.
My preference is to omit the return value unless I return failure, then I return success explicitly as well:
int main()
{
// Don't return anything explicitly
}#include <cstdlib>
using namespace std;
int main()
{
if ( some_failure )
return EXIT_FAILURE; // Return failure here
return EXIT_SUCCESS; // And success here
}No, an empty block is legal. It's roughly equivalent to:
if ( something ) ;
I'm a programmer. My attitude starts with arrogance, holds steady at condescension, and ends with hostility. Get used to it.
•
•
Join Date: Jul 2007
Posts: 2
Reputation:
Rep Power: 0
Solved Threads: 1
•
•
•
•
is there anyway to print out any string on stdout without using semicolon at the end... ?? plzz reply
If you want to just output anything without semicolon at the end ...then u can simply shift the semicolon to the next line i.e
1.printf("hello world")
2.; // semicolon is used to terminate statements so it can be shifted to next line
or
1. cout<<"Hello world"
2. ;
isnt semicolon at the end of any statements a required syntax in C and C++??
if thats so, that cant be possible unless modifying the whole language(Not C anymore)..
if thats so, that cant be possible unless modifying the whole language(Not C anymore)..
Not necessarily, it was a trick question. See this.
"I don't accept change. I don't deserve to live."
"Working a real job is a win if you're lazy, greedy, or unmotivated. If you're average, you fit right in. And if you're above average, the basic terms of employment and premise of the arrangement is against your interests."
"Working a real job is a win if you're lazy, greedy, or unmotivated. If you're average, you fit right in. And if you're above average, the basic terms of employment and premise of the arrangement is against your interests."
![]() |
•
•
•
•
•
•
•
•
DaniWeb C Marketplace
•
•
•
•
Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
Similar Threads
- microsoft access simple date query (Computer Science and Software Design)
Other Threads in the C Forum
- Previous Thread: Possible Project in C
- Next Thread: Help could any one look to my code and answer my question?



Linear Mode