<?xml version="1.0" encoding="utf-8"?>
<rss version="2.0">
  <channel>
    <title>'POINTERS AND STRINGS' Thread RSS Feed</title>
    <link>http://www.programmersheaven.com/</link>
    <description>Contains the latest posts from the thread 'POINTERS AND STRINGS' posted on the 'Beginner C/C++' forum at Programmer's Heaven.</description>
    <language>en</language>
    <copyright>Copyright 2008 Programmers Heaven</copyright>
    <pubDate>Mon, 01 Dec 2008 19:42:48 -0700</pubDate>
    <lastBuildDate>Mon, 01 Dec 2008 19:42:48 -0700</lastBuildDate>
    <generator>Argotic Syndication Framework 2007.3.0.1, http://www.codeplex.com/Argotic</generator>
    <docs>http://www.rssboard.org/rss-specification</docs>
    <ttl>360</ttl>
    <image>
      <url>http://www.programmersheaven.com/images/ph.gif</url>
      <title>Programmers Heaven</title>
      <link>http://www.programmersheaven.com/</link>
      <width>88</width>
      <height>31</height>
    </image>
    <item>
      <title>POINTERS AND STRINGS</title>
      <link>http://www.programmersheaven.com/mb/beginnercpp/373149/373149/pointers-and-strings/</link>
      <description>#include&amp;lt;stdio.h&amp;gt;&lt;br /&gt;
#include&amp;lt;conio.h&amp;gt;&lt;br /&gt;
#include&amp;lt;math.h&amp;gt;&lt;br /&gt;
void main()&lt;br /&gt;
{&lt;br /&gt;
clrscr();&lt;br /&gt;
char *str1="uvce";&lt;br /&gt;
char str2[]="uvce";&lt;br /&gt;
printf("%d %d %d",sizeof(str1),sizeof(str2),sizeof("abcd"));&lt;br /&gt;
printf("\n%u",str2);&lt;br /&gt;
getch();&lt;br /&gt;
}&lt;br /&gt;
I'M USING TURBO C++ COMPILER.WHY IS THE OUTPUT COMING OUT TO BE &lt;br /&gt;
2 5 5&lt;br /&gt;
PLEASE HELP ME OUT.&lt;br /&gt;</description>
      <pubDate>Fri, 04 Jul 2008 23:52:04 -0700</pubDate>
      <category>Beginner C/C++</category>
    </item>
    <item>
      <title>Re: POINTERS AND STRINGS</title>
      <link>http://www.programmersheaven.com/mb/beginnercpp/373149/373150/re-pointers-and-strings/#373150</link>
      <description>In the first case you are taking the size of a pointer, not an array. Pointers are 16-bit on Turbo C, since it is an ancient compiler. In the other cases you are taking the size of strings (arrays). All strings surrounded by "" are automatically null-terminated, containing a null character at the end, which gives the size 5.</description>
      <pubDate>Sat, 05 Jul 2008 00:49:22 -0700</pubDate>
      <category>Beginner C/C++</category>
    </item>
    <item>
      <title>Re: POINTERS AND STRINGS</title>
      <link>http://www.programmersheaven.com/mb/beginnercpp/373149/373151/re-pointers-and-strings/#373151</link>
      <description>: void main()&lt;br /&gt;
&lt;br /&gt;
main is of return type int. See references 1-5.&lt;br /&gt;
&lt;br /&gt;
References&lt;br /&gt;
&lt;br /&gt;
* 1) C++. International Standard. ISO/IEC 14882. Second edition. Paragraph 3.6.1.2&lt;br /&gt;
&lt;br /&gt;
* 2) From &lt;a href="http://www.parashift.com/c++-faq-lite/newbie.html#faq-29.3"&gt;http://www.parashift.com/c++-faq-lite/newbie.html#faq-29.3&lt;/a&gt; : main() must return int. Not void, not bool, not float. int. Just int, nothing but int, only int. Some compilers accept void main(), but that is non-standard and shouldn't be used. Instead use int main().&lt;br /&gt;
&lt;br /&gt;
* 3) Herb Sutter. Exceptional C++. ISBN: 0-201-61562-2. Item 21: void main() is nonstandard and nonportable.&lt;br /&gt;
&lt;br /&gt;
* 4) From Bjarne Stroustrup's homepage (http://www.research.att.com/~bs/bs_faq2.html#void-main) :&lt;br /&gt;
&lt;br /&gt;
The definition&lt;br /&gt;
&lt;br /&gt;
void main() { /* ... */ }&lt;br /&gt;
&lt;br /&gt;
is not and never has been C++, nor has it even been C.&lt;br /&gt;
&lt;br /&gt;
* 5) From the The alt.comp.lang.learn.c-c++ FAQ: &lt;a href="http://ma.rtij.nl/acllc-c++.FAQ.html#q3.4:"&gt;http://ma.rtij.nl/acllc-c++.FAQ.html#q3.4:&lt;/a&gt; 3.4 Why does everyone make so much fuss about "void main()"?. Because the return type of the main() function must be int in both C and C++. Anything else is undefined. Bottom line - don't try to start a thread about this in alt.comp.lang.learn.c-c++ as it has already been discussed many, many times and generates more flamage than any other topic.&lt;br /&gt;</description>
      <pubDate>Sat, 05 Jul 2008 01:25:39 -0700</pubDate>
      <category>Beginner C/C++</category>
    </item>
    <item>
      <title>Re: POINTERS AND STRINGS</title>
      <link>http://www.programmersheaven.com/mb/beginnercpp/373149/373165/re-pointers-and-strings/#373165</link>
      <description>Hehe, well he is writing in C. The C standard states that main() shall return int if the program is running in a "hosted environment", such as on Windows / Linux / Mac. If the program is running without a "host OS", then it doesn't make much sense to return anything, and in that case the C standard allows it.&lt;br /&gt;
&lt;br /&gt;
Personally I always use int main() even if I'm writing low-level hardware stuff, because if I do I can test the code on a Windows compiler. In such programs, the program counter will never reach the end of main, so it really doesn't matter if main returns anything or not.</description>
      <pubDate>Sun, 06 Jul 2008 02:30:50 -0700</pubDate>
      <category>Beginner C/C++</category>
    </item>
    <item>
      <title>Re: POINTERS AND STRINGS</title>
      <link>http://www.programmersheaven.com/mb/beginnercpp/373149/373169/re-pointers-and-strings/#373169</link>
      <description>: Hehe, well he is writing in C. The C standard states that main() &lt;br /&gt;
: shall return int if the program is running in a "hosted &lt;br /&gt;
: environment", such as on Windows / Linux / Mac. If the program is &lt;br /&gt;
: running without a "host OS", then it doesn't make much sense to &lt;br /&gt;
: return anything, and in that case the C standard allows it.&lt;br /&gt;
: &lt;br /&gt;
: Personally I always use int main() even if I'm writing low-level &lt;br /&gt;
: hardware stuff, because if I do I can test the code on a Windows &lt;br /&gt;
: compiler. In such programs, the program counter will never reach the &lt;br /&gt;
: end of main, so it really doesn't matter if main returns anything or &lt;br /&gt;
: not.&lt;br /&gt;
&lt;br /&gt;
Lundin, PLEASE don't argue on this. Are five references to the literature not enough for you? Or do you want to support newbies to incorrectly use void main()?&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
bilderbikkel</description>
      <pubDate>Sun, 06 Jul 2008 09:26:14 -0700</pubDate>
      <category>Beginner C/C++</category>
    </item>
    <item>
      <title>Re: POINTERS AND STRINGS</title>
      <link>http://www.programmersheaven.com/mb/beginnercpp/373149/373171/re-pointers-and-strings/#373171</link>
      <description>: Lundin, PLEASE don't argue on this. Are five references to the &lt;br /&gt;
: literature not enough for you? Or do you want to support newbies to &lt;br /&gt;
: incorrectly use void main()?&lt;br /&gt;
&lt;br /&gt;
Lundin is referring to the C standard, not the C++ standard. In any case, C99 section 5.1.2.2.1 displays only two forms on a hosted envirement:&lt;br /&gt;
&lt;br /&gt;
&lt;pre class="sourcecode"&gt;int main ();
int main (int argc, char* argv[]);&lt;/pre&gt;&lt;br /&gt;
If the program is not running in a hosted envirement (section 5.1.2.1), the entry point is implementation defined, so do not need to follow the above forms (Nor even use main() ). I think this is what Lundin was referring to.&lt;br /&gt;
&lt;br /&gt;
In any case, the OP is running on a hosted envirement (As correctly pointed out), so he should be using one of the two forms shown above.&lt;br /&gt;
&lt;br /&gt;
&lt;hr /&gt;&lt;span style="font-size: xx-small;"&gt;&amp;#91;.:EvolutionEngine&amp;#93;&amp;#91;.:MicroOS Operating System&amp;#93;&amp;#91;&lt;a href="http://www.brokenthorn.com"&gt;Website :: OS Development Series&amp;#93;&lt;/a&gt;&lt;/span&gt;&lt;br /&gt;</description>
      <pubDate>Sun, 06 Jul 2008 11:39:41 -0700</pubDate>
      <category>Beginner C/C++</category>
    </item>
    <item>
      <title>Re: POINTERS AND STRINGS</title>
      <link>http://www.programmersheaven.com/mb/beginnercpp/373149/373180/re-pointers-and-strings/#373180</link>
      <description>Correct, I am referring to C not C++.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
ISO 9899:1999 "Programming Languages - C"&lt;br /&gt;
&lt;br /&gt;
5.1.2.1 Freestanding environment&lt;br /&gt;
&lt;br /&gt;
"1 In a freestanding environment (in which C program execution may take place without any benefit of an operating system), the name and type of the function called at program startup are implementation-defined. Any library facilities available to a freestanding program, other than the minimal set required by clause 4, are implementation-defined.&lt;br /&gt;
&lt;br /&gt;
2 The effect of program termination in a freestanding environment is implementation-defined."&lt;br /&gt;
&lt;br /&gt;
5.1.2.2 Hosted environment&lt;br /&gt;
&lt;br /&gt;
"1  A hosted environment need not be provided, but shall conform to the following specifications if present."&lt;br /&gt;
&lt;br /&gt;
5.1.2.2.1 Program startup&lt;br /&gt;
&lt;br /&gt;
"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:&lt;br /&gt;
&lt;br /&gt;
int main(void) { /* ... */ }&lt;br /&gt;
&lt;br /&gt;
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):&lt;br /&gt;
&lt;br /&gt;
int main(int argc, char *argv[]) { /* ... */ }&lt;br /&gt;
&lt;br /&gt;
or equivalent;9) or in some other implementation-defined manner."&lt;br /&gt;
&lt;br /&gt;
"9) Thus, int can be replaced by a typedef name defined as int, or the type of argv can be written as char ** argv, and so on."&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
Annex J, J2 Undefined behavior&lt;br /&gt;
&lt;br /&gt;
"A program in a hosted environment does not define a function named main using one of the specified forms (5.1.2.2.1)."</description>
      <pubDate>Sun, 06 Jul 2008 23:13:54 -0700</pubDate>
      <category>Beginner C/C++</category>
    </item>
    <item>
      <title>Re: POINTERS AND STRINGS</title>
      <link>http://www.programmersheaven.com/mb/beginnercpp/373149/373369/re-pointers-and-strings/#373369</link>
      <description>Hi Lundin,&lt;br /&gt;
&lt;br /&gt;
I like people quoting the C (or C++) Standard. It shows people take programming serious.&lt;br /&gt;
&lt;br /&gt;
: "A program in a hosted environment does not define a function named &lt;br /&gt;
: main using one of the specified forms (5.1.2.2.1)."&lt;br /&gt;
&lt;br /&gt;
But what I still disagree is posting that 'main' can have return type void. Yes, it can, in a hosted environment. But 'int main' is always correct. Please support people teaching newbies to use 'int main'.&lt;br /&gt;
&lt;br /&gt;
I hope you can contribute to our newbies writing the correct-in-100%-of-the-cases 'int main', instead of defending them writing also-valid-in-1%-of-the-cases 'void main'.&lt;br /&gt;
&lt;br /&gt;
See ya, Bilderbikkel&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;</description>
      <pubDate>Sun, 13 Jul 2008 09:50:36 -0700</pubDate>
      <category>Beginner C/C++</category>
    </item>
    <item>
      <title>Re: POINTERS AND STRINGS</title>
      <link>http://www.programmersheaven.com/mb/beginnercpp/373149/373374/re-pointers-and-strings/#373374</link>
      <description>Embedded systems is probably 90% of the computers in the world... but point taken since this is the beginner forum &lt;img src="http://www.programmersheaven.com/images/Community/smile.gif" width="15" height="15" alt="" /&gt;&lt;br /&gt;
&lt;br /&gt;
If you are a newbie, you should probably skip this post, always write int main() and don't ponder on why you do it. It is a rather advanced and somewhat pointless topic &lt;img src="http://www.programmersheaven.com/images/Community/twink.gif" width="15" height="15" alt="" /&gt;</description>
      <pubDate>Sun, 13 Jul 2008 11:39:19 -0700</pubDate>
      <category>Beginner C/C++</category>
    </item>
  </channel>
</rss>