Connect with us

C programming, function returning a garbage value

Discussion in 'Microcontrollers, Programming and IoT' started by Luke Vassallo, Mar 26, 2015.

Scroll to continue with content
  1. Luke Vassallo

    Luke Vassallo

    Dec 10, 2014

    I am creating a program that will check for a number if a number is prime or not. However the function is returning a garbage number when I use local variables.(works fine with global though)

    the code looks fine to me however I can't understand what's going wrong.

    this is the function

  2. Gryd3


    Jun 25, 2014
    Can you post the section of code that calls the function as well?
  3. Luke Vassallo

    Luke Vassallo

    Dec 10, 2014
    I fixed the problem. It was expecting that after the function is executed it's value will be changed to either a 1 or a 0. But then I called the function to execute the code and use the returned value immediately.

    I was thinking of it the wrong way, it actually returns a value and not change the function's value itself
    Gryd3 likes this.
Ask a Question
Want to reply to this thread or ask your own question?
You'll need to choose a username for the site, which only take a couple of moments (here). After that, you can post your question and our members will help you out.
Electronics Point Logo
Continue to site
Quote of the day