<?xml version="1.0" encoding="utf-8"?>
<rss version="2.0">
  <channel>
    <title>'Strange results from the C program' Thread RSS Feed</title>
    <link>http://www.programmersheaven.com/</link>
    <description>Contains the latest posts from the thread 'Strange results from the C program' posted on the 'C and C++' forum at Programmer's Heaven.</description>
    <language>en</language>
    <copyright>Copyright 2013 Programmers Heaven</copyright>
    <pubDate>Sat, 25 May 2013 17:28:23 -0700</pubDate>
    <lastBuildDate>Sat, 25 May 2013 17:28:23 -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>Strange results from the C program</title>
      <link>http://www.programmersheaven.com/mb/CandCPP/429756/429756/strange-results-from-the-c-program/</link>
      <description>Hello, I am getting up to speed with C during the week and I have written one of my first programs and I do not understand why the return of the function. If I input X as 3, Y as 4 and N as 6 I get the return as several million. I should be getting the return of check funtion as 1 with those inputs.&lt;br /&gt;
&lt;br /&gt;
#include &amp;lt;stdio.h&amp;gt;&lt;br /&gt;
&lt;br /&gt;
int check(int x,int y,int n);&lt;br /&gt;
&lt;br /&gt;
int main(void)&lt;br /&gt;
{&lt;br /&gt;
    int x,y,n;&lt;br /&gt;
    printf("\nValue of X: ");&lt;br /&gt;
    scanf("%d", &amp;amp;x);&lt;br /&gt;
&lt;br /&gt;
    printf("\nValue of Y: ");&lt;br /&gt;
    scanf("%d", &amp;amp;y);&lt;br /&gt;
&lt;br /&gt;
    printf("\nValue of N: ");&lt;br /&gt;
    scanf("%d", &amp;amp;n);&lt;br /&gt;
&lt;br /&gt;
    check(x,y,n);&lt;br /&gt;
    printf("check = %d", check);&lt;br /&gt;
    if (check == 1){&lt;br /&gt;
        printf("\vx and y checked out.");&lt;br /&gt;
    }&lt;br /&gt;
    else if (check == 0){&lt;br /&gt;
        printf("Digits failed the check");&lt;br /&gt;
    }&lt;br /&gt;
}&lt;br /&gt;
&lt;br /&gt;
int check(int x,int y,int n)&lt;br /&gt;
{&lt;br /&gt;
    int i=0;&lt;br /&gt;
    if (x&amp;gt;0 &amp;amp;&amp;amp; x&amp;lt;(n-1)){&lt;br /&gt;
        if (y&amp;gt;0 &amp;amp;&amp;amp; y&amp;lt;(n-1)){&lt;br /&gt;
            return 1;&lt;br /&gt;
        }&lt;br /&gt;
    }&lt;br /&gt;
&lt;br /&gt;
}&lt;br /&gt;
&lt;br /&gt;</description>
      <guid isPermaLink="true">http://www.programmersheaven.com/mb/CandCPP/429756/429756/strange-results-from-the-c-program/</guid>
      <pubDate>Tue, 09 Oct 2012 07:41:43 -0700</pubDate>
      <category>C and C++</category>
    </item>
    <item>
      <title>Re: Strange results from the C program</title>
      <link>http://www.programmersheaven.com/mb/CandCPP/429756/429757/re-strange-results-from-the-c-program/#429757</link>
      <description>Because if your IFs fail, you don't return anything at all.&lt;br /&gt;</description>
      <guid isPermaLink="true">http://www.programmersheaven.com/mb/CandCPP/429756/429757/re-strange-results-from-the-c-program/#429757</guid>
      <pubDate>Tue, 09 Oct 2012 08:52:16 -0700</pubDate>
      <category>C and C++</category>
    </item>
    <item>
      <title>Re: Strange results from the C program</title>
      <link>http://www.programmersheaven.com/mb/CandCPP/429756/429758/re-strange-results-from-the-c-program/#429758</link>
      <description>Because if your IFs fail, you don't return anything at all.&lt;br /&gt;</description>
      <guid isPermaLink="true">http://www.programmersheaven.com/mb/CandCPP/429756/429758/re-strange-results-from-the-c-program/#429758</guid>
      <pubDate>Tue, 09 Oct 2012 08:54:06 -0700</pubDate>
      <category>C and C++</category>
    </item>
    <item>
      <title>Re: Strange results from the C program</title>
      <link>http://www.programmersheaven.com/mb/CandCPP/429756/429760/re-strange-results-from-the-c-program/#429760</link>
      <description>Hi Kotik..&lt;br /&gt;
&lt;br /&gt;
I think it's because you call  check function directly without put it into variabel.&lt;br /&gt;
Please try this code , maybe it help you.&lt;br /&gt;
&lt;br /&gt;
#include &amp;lt;stdio.h&amp;gt;&lt;br /&gt;
&lt;br /&gt;
int main(void)&lt;br /&gt;
{&lt;br /&gt;
int x,y,n;&lt;br /&gt;
&lt;strong&gt;int z;&lt;/strong&gt;&lt;br /&gt;
printf("\nValue of X: ");&lt;br /&gt;
scanf("%d", &amp;amp;x);&lt;br /&gt;
&lt;br /&gt;
printf("\nValue of Y: ");&lt;br /&gt;
scanf("%d", &amp;amp;y);&lt;br /&gt;
&lt;br /&gt;
printf("\nValue of N: ");&lt;br /&gt;
scanf("%d", &amp;amp;n);&lt;br /&gt;
&lt;br /&gt;
&lt;strong&gt;z = check(x,y,n);&lt;br /&gt;
printf("check = %d", z);&lt;/strong&gt;&lt;br /&gt;
if (z == 1){&lt;br /&gt;
printf("\vx and y checked out.");&lt;br /&gt;
}&lt;br /&gt;
else if (check == 0){&lt;br /&gt;
printf("Digits failed the check");&lt;br /&gt;
}&lt;br /&gt;
}&lt;br /&gt;
&lt;br /&gt;
int check(int x,int y,int n)&lt;br /&gt;
{&lt;br /&gt;
int i=0;&lt;br /&gt;
if (x&amp;gt;0 &amp;amp;&amp;amp; x&amp;lt;(n-1)){&lt;br /&gt;
if (y&amp;gt;0 &amp;amp;&amp;amp; y&amp;lt;(n-1)){&lt;br /&gt;
return 1;&lt;br /&gt;
}&lt;br /&gt;
}&lt;br /&gt;
&lt;br /&gt;
}&lt;br /&gt;</description>
      <guid isPermaLink="true">http://www.programmersheaven.com/mb/CandCPP/429756/429760/re-strange-results-from-the-c-program/#429760</guid>
      <pubDate>Tue, 09 Oct 2012 19:52:41 -0700</pubDate>
      <category>C and C++</category>
    </item>
    <item>
      <title>Re: Strange results from the C program</title>
      <link>http://www.programmersheaven.com/mb/CandCPP/429756/429761/re-strange-results-from-the-c-program/#429761</link>
      <description>: Hello, I am getting up to speed with C during the week and I have &lt;br /&gt;
: written one of my first programs and I do not understand why the &lt;br /&gt;
: return of the function. If I input X as 3, Y as 4 and N as 6 I get &lt;br /&gt;
: the return as several million. I should be getting the return of &lt;br /&gt;
: check funtion as 1 with those inputs.&lt;br /&gt;
: &lt;br /&gt;
: #include &amp;lt;stdio.h&amp;gt;&lt;br /&gt;
: &lt;br /&gt;
: int check(int x,int y,int n);&lt;br /&gt;
: &lt;br /&gt;
: int main(void)&lt;br /&gt;
: {&lt;br /&gt;
:     int x,y,n;&lt;br /&gt;
:     printf("\nValue of X: ");&lt;br /&gt;
:     scanf("%d", &amp;amp;x);&lt;br /&gt;
: &lt;br /&gt;
:     printf("\nValue of Y: ");&lt;br /&gt;
:     scanf("%d", &amp;amp;y);&lt;br /&gt;
: &lt;br /&gt;
:     printf("\nValue of N: ");&lt;br /&gt;
:     scanf("%d", &amp;amp;n);&lt;br /&gt;
: &lt;br /&gt;
:     check(x,y,n);&lt;br /&gt;
:     printf("check = %d", check);&lt;br /&gt;
:     if (check == 1){&lt;br /&gt;
:         printf("\vx and y checked out.");&lt;br /&gt;
:     }&lt;br /&gt;
:     else if (check == 0){&lt;br /&gt;
:         printf("Digits failed the check");&lt;br /&gt;
:     }&lt;br /&gt;
: }&lt;br /&gt;
: &lt;br /&gt;
: int check(int x,int y,int n)&lt;br /&gt;
: {&lt;br /&gt;
:     int i=0;&lt;br /&gt;
:     if (x&amp;gt;0 &amp;amp;&amp;amp; x&amp;lt;(n-1)){&lt;br /&gt;
:         if (y&amp;gt;0 &amp;amp;&amp;amp; y&amp;lt;(n-1)){&lt;br /&gt;
:             return 1;&lt;br /&gt;
:         }&lt;br /&gt;
:     }&lt;br /&gt;
: &lt;br /&gt;
: }&lt;br /&gt;
: &lt;br /&gt;
: &lt;br /&gt;
Hi Kotik..&lt;br /&gt;
&lt;br /&gt;
I think it's because you call  check function directly without put it into variabel.&lt;br /&gt;
Please try this code , maybe it help you.&lt;br /&gt;
&lt;br /&gt;
#include &amp;lt;stdio.h&amp;gt;&lt;br /&gt;
&lt;br /&gt;
int main(void)&lt;br /&gt;
{&lt;br /&gt;
int x,y,n;&lt;br /&gt;
&lt;strong&gt;int z;&lt;/strong&gt;&lt;br /&gt;
printf("\nValue of X: ");&lt;br /&gt;
scanf("%d", &amp;amp;x);&lt;br /&gt;
&lt;br /&gt;
printf("\nValue of Y: ");&lt;br /&gt;
scanf("%d", &amp;amp;y);&lt;br /&gt;
&lt;br /&gt;
printf("\nValue of N: ");&lt;br /&gt;
scanf("%d", &amp;amp;n);&lt;br /&gt;
&lt;br /&gt;
&lt;strong&gt;z = check(x,y,n);&lt;br /&gt;
printf("check = %d", z);&lt;/strong&gt;&lt;br /&gt;
if (z == 1){&lt;br /&gt;
printf("\vx and y checked out.");&lt;br /&gt;
}&lt;br /&gt;
else if (check == 0){&lt;br /&gt;
printf("Digits failed the check");&lt;br /&gt;
}&lt;br /&gt;
}&lt;br /&gt;
&lt;br /&gt;
int check(int x,int y,int n)&lt;br /&gt;
{&lt;br /&gt;
int i=0;&lt;br /&gt;
if (x&amp;gt;0 &amp;amp;&amp;amp; x&amp;lt;(n-1)){&lt;br /&gt;
if (y&amp;gt;0 &amp;amp;&amp;amp; y&amp;lt;(n-1)){&lt;br /&gt;
return 1;&lt;br /&gt;
}&lt;br /&gt;
}&lt;br /&gt;
&lt;br /&gt;
}&lt;br /&gt;</description>
      <guid isPermaLink="true">http://www.programmersheaven.com/mb/CandCPP/429756/429761/re-strange-results-from-the-c-program/#429761</guid>
      <pubDate>Tue, 09 Oct 2012 19:55:53 -0700</pubDate>
      <category>C and C++</category>
    </item>
    <item>
      <title>Re: Strange results from the C program</title>
      <link>http://www.programmersheaven.com/mb/CandCPP/429756/429989/re-strange-results-from-the-c-program/#429989</link>
      <description>you are getting such results in printf statement because you have written your statement as &lt;br /&gt;
&lt;br /&gt;
&lt;strong&gt;printf("check = %d", check);&lt;/strong&gt;&lt;br /&gt;
&lt;br /&gt;
What this will do is print the address where your function is present in the memory. But if your statement as &lt;br /&gt;
&lt;br /&gt;
&lt;strong&gt;printf("check = %d", check());&lt;/strong&gt;&lt;br /&gt;
&lt;br /&gt;
which I thing you intended for.&lt;br /&gt;
&lt;br /&gt;
One more thing you should rewrite your check method/function, as if conditions are not satisfied you will end up in returning a garbage value to your return statement. For beginners it is prefered to code in the way our other fellow programmers have modified your code.&lt;br /&gt;</description>
      <guid isPermaLink="true">http://www.programmersheaven.com/mb/CandCPP/429756/429989/re-strange-results-from-the-c-program/#429989</guid>
      <pubDate>Mon, 29 Oct 2012 23:15:34 -0700</pubDate>
      <category>C and C++</category>
    </item>
  </channel>
</rss>