473,836 Members | 1,495 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

cin/cout vs. scanf/printf

Hello, I have question (or 2 :)). Is that true that for a large data
using scanf/printf instead of cin/cout makes that the program runs
faster? And if it is, is it legal to mix scanf/printf with C++ code?
Program should execute below 1 sec and the hint is to use scanf/printf.

Aug 3 '06
25 9744

Victor Bazarov wrote:
Avtually, that's not true. C requres 'int main(void)'. The 'void'
is necessary.
Not according to the FAQ.

http://c-faq.com/ansi/maindecl.html

I know why you believe it is, and maybe the faq is wrong...it's the
only authority I could find. A common C definition of main is:

main()
{
return 0;
}

I was trying to find something that speaks to the unspecified nature of
the accepted parameters in that declaration but couldn't coax google
into giving me any. The FAQ would lead one to believe it is ok.

Aug 4 '06 #21
Noah Roberts posted:
A common C definition of main is:

main()
{
return 0;
}

That's valid in C89.

In C99, the implicit return value of "int" no longer applies.

Furthermore, in C, empty parentheses only specify a variable length
argument list if it's a declaration:

void Func(); /* Might be variable length */

void Func() /* Takes no arguments */
{

}

The most "proper" way of defining main in C is:

int main(void) {...

Although there's nothing wrong with:

int main()

(But they'd don't like empty parentheses.)

--

Frederick Gotham
Aug 4 '06 #22
Noah Roberts wrote:
>
Victor Bazarov wrote:
Avtually, that's not true. C requres 'int main(void)'. The 'void'
is necessary.

Not according to the FAQ.

http://c-faq.com/ansi/maindecl.html
Actually, the FAQ supports what Victor said.

The C99 Standard says:

5.1.2.2.1 Program startup

[#1] The function called at program startup is named main.
The implementation declares no prototype for this function.
It shall be defined with a return type of int and with no
parameters:

int main(void) { /* ... */ }

or with two parameters (referred to here as argc and argv,
though any names may be used, as they are local to the
function in which they are declared):

int main(int argc, char *argv[]) { /* ... */ }

or equivalent;8) or in some other implementation-defined
manner.

I know why you believe it is, and maybe the faq is wrong...it's the
only authority I could find. A common C definition of main is:

main()
{
return 0;
}
Common doesn't make it correct.
I was trying to find something that speaks to the unspecified nature
of the accepted parameters in that declaration but couldn't coax
google into giving me any. The FAQ would lead one to believe it is
ok.
That what is ok? Leaving out the void? It doesn't say that.

Brian
Aug 4 '06 #23
Default User wrote:
Noah Roberts wrote:

Victor Bazarov wrote:
Avtually, that's not true. C requres 'int main(void)'. The
'void' is necessary.
Not according to the FAQ.

http://c-faq.com/ansi/maindecl.html

Actually, the FAQ supports what Victor said.
From your follow-up question on comp.lang.c, I understand now what you
were getting at. Disregard this.

Brian
Aug 4 '06 #24

Default User wrote:
The C99 Standard says:

5.1.2.2.1 Program startup

[#1] The function called at program startup is named main.
The implementation declares no prototype for this function.
It shall be defined with a return type of int and with no
parameters:

int main(void) { /* ... */ }

or with two parameters (referred to here as argc and argv,
though any names may be used, as they are local to the
function in which they are declared):

int main(int argc, char *argv[]) { /* ... */ }

or equivalent;8) or in some other implementation-defined
manner.
Ok, this is getting a little OT so I'm labeling it such...

That last statement is something I find interesting. Assuming that
"implementa tion-defined" is the same in C as it is in C++ then by that
statement "void main()" would be perfectly /valid/ (even if not
portable) in some implementation that defines it as being such.

Aug 4 '06 #25
Noah Roberts wrote:
>
Default User wrote:
The C99 Standard says:

5.1.2.2.1 Program startup

[#1] The function called at program startup is named main.
The implementation declares no prototype for this function.
It shall be defined with a return type of int and with no
parameters:

int main(void) { /* ... */ }

or with two parameters (referred to here as argc and argv,
though any names may be used, as they are local to the
function in which they are declared):

int main(int argc, char *argv[]) { /* ... */ }

or equivalent;8) or in some other implementation-defined
manner.

Ok, this is getting a little OT so I'm labeling it such...

That last statement is something I find interesting. Assuming that
"implementa tion-defined" is the same in C as it is in C++ then by that
statement "void main()" would be perfectly valid (even if not
portable) in some implementation that defines it as being such.

I assume so. The C++ standard is a bit firmer in that regard, mandating
the return type but allowing the rest of the type to be
implementation-defined. This is, I assume, to support legacy stuff like
the env parameter. I don't know that C was trying specifically to allow
void return types, but frankly I don't see it as precluding them either.


Brian
Aug 4 '06 #26

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

2
3049
by: nrhayyal | last post by:
Hello experts, are cout and printf and other ostream and stdio functions/libraries are threadsafe? i am using gnu gcc3.3.2 on AIX5.2. and my applications are multithreaded applications. i am using -lpthread as one of the compiler option. i am using cout and printf for debugging purpose. thanks for ur replies in advance. Thanks and Regards
15
7074
by: pereges | last post by:
have i written this program correctly ? it is giving me correct output but i am little suspicious in the following two statements - scanf("%d", &ptr->data) and printf("%d\n", ptr->data). /********** LINK LIST **********/ #include <stdio.h>
0
9813
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, weíll explore What is ONU, What Is Router, ONU & Routerís main usage, and What is the difference between ONU and Router. Letís take a closer look ! Part I. Meaning of...
0
10541
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
1
10584
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
10248
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
0
6976
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
5645
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
0
5817
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
2
4006
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
3
3108
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.