User Name Password Register
DaniWeb IT Discussion Community
All
What is DaniWeb IT Discussion Community?
You're currently browsing the C section within the Software Development category of DaniWeb, a massive community of 361,896 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,346 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:
Views: 2301 | Replies: 16
Reply
Join Date: Nov 2004
Location: India
Posts: 57
Reputation: harshchandra is an unknown quantity at this point 
Rep Power: 0
Solved Threads: 1
harshchandra harshchandra is offline Offline
Junior Poster in Training

simple query about cout

  #1  
Apr 2nd, 2005
is there anyway to print out any string on stdout without using semicolon at the end... ?? plzz reply
AddThis Social Bookmark Button
Reply With Quote  
Join Date: Sep 2004
Posts: 5,839
Reputation: Narue is a splendid one to behold Narue is a splendid one to behold Narue is a splendid one to behold Narue is a splendid one to behold Narue is a splendid one to behold Narue is a splendid one to behold Narue is a splendid one to behold Narue is a splendid one to behold 
Rep Power: 24
Solved Threads: 384
Super Moderator
Narue's Avatar
Narue Narue is offline Offline
Expert Meanie

Re: simple query about cout

  #2  
Apr 2nd, 2005
I have no idea what you just asked. Be more specific.
Member of: Beautiful Code Club.
Reply With Quote  
Join Date: Nov 2004
Location: India
Posts: 57
Reputation: harshchandra is an unknown quantity at this point 
Rep Power: 0
Solved Threads: 1
harshchandra harshchandra is offline Offline
Junior Poster in Training

Re: simple query about cout

  #3  
Apr 6th, 2005
according to the c rules every statement must be terminated with a semicolon...i want to kmow that how can i use cout / printf statement to print any string without using semicolon at the end... ?????
Reply With Quote  
Join Date: Sep 2004
Posts: 5,839
Reputation: Narue is a splendid one to behold Narue is a splendid one to behold Narue is a splendid one to behold Narue is a splendid one to behold Narue is a splendid one to behold Narue is a splendid one to behold Narue is a splendid one to behold Narue is a splendid one to behold 
Rep Power: 24
Solved Threads: 384
Super Moderator
Narue's Avatar
Narue Narue is offline Offline
Expert Meanie

Re: simple query about cout

  #4  
Apr 6th, 2005
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 ) {
  }
}
Member of: Beautiful Code Club.
Reply With Quote  
Join Date: Nov 2004
Location: India
Posts: 57
Reputation: harshchandra is an unknown quantity at this point 
Rep Power: 0
Solved Threads: 1
harshchandra harshchandra is offline Offline
Junior Poster in Training

Re: simple query about cout

  #5  
Apr 7th, 2005
Thanx I got that cool twist
Reply With Quote  
Join Date: Jan 2005
Posts: 188
Reputation: Fasola is an unknown quantity at this point 
Rep Power: 4
Solved Threads: 0
Fasola Fasola is offline Offline
Junior Poster

Re: simple query about cout

  #6  
Apr 7th, 2005
that can't be correct, Na I thought you told me int main() has to return something? Nothing was returned :evil:

hahahaha...seriously, don't you have to put something inside the braces?
Reply With Quote  
Join Date: Sep 2004
Posts: 5,839
Reputation: Narue is a splendid one to behold Narue is a splendid one to behold Narue is a splendid one to behold Narue is a splendid one to behold Narue is a splendid one to behold Narue is a splendid one to behold Narue is a splendid one to behold Narue is a splendid one to behold 
Rep Power: 24
Solved Threads: 384
Super Moderator
Narue's Avatar
Narue Narue is offline Offline
Expert Meanie

Re: simple query about cout

  #7  
Apr 7th, 2005
>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:
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
}
>don't you have to put something inside the braces?
No, an empty block is legal. It's roughly equivalent to:
if ( something )
  ;
But that uses a semicolon, so it's not a valid solution for the problem.
Member of: Beautiful Code Club.
Reply With Quote  
Join Date: Jul 2007
Posts: 2
Reputation: koder is an unknown quantity at this point 
Rep Power: 0
Solved Threads: 1
koder koder is offline Offline
Newbie Poster

Re: simple query about cout

  #8  
Jul 7th, 2007
Originally Posted by harshchandra View Post
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. ;
Reply With Quote  
Join Date: Mar 2007
Posts: 21
Reputation: iTaChi is an unknown quantity at this point 
Rep Power: 2
Solved Threads: 2
iTaChi's Avatar
iTaChi iTaChi is offline Offline
Newbie Poster

Re: simple query about cout

  #9  
Jul 8th, 2007
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 you understand, you can learn anything"


http://www.cprogrammingdock.serverspeople.net
Reply With Quote  
Join Date: Jun 2006
Location: India
Posts: 6,691
Reputation: ~s.o.s~ is a splendid one to behold ~s.o.s~ is a splendid one to behold ~s.o.s~ is a splendid one to behold ~s.o.s~ is a splendid one to behold ~s.o.s~ is a splendid one to behold ~s.o.s~ is a splendid one to behold ~s.o.s~ is a splendid one to behold 
Rep Power: 23
Solved Threads: 312
Moderator
Featured Poster
~s.o.s~'s Avatar
~s.o.s~ ~s.o.s~ is offline Offline
Rebellion Revamped

Re: simple query about cout

  #10  
Jul 8th, 2007
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."
Reply With Quote  
Reply

Only community members can participate in forum threads. You must register or log in to contribute.

Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)

 

DaniWeb C Marketplace
Thread Tools Display Modes

Similar Threads
Other Threads in the C Forum

All times are GMT -4. The time now is 8:29 pm.
Forum system based on vBulletin Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
©2003 - 2008 DaniWeb® LLC