0

I have dynamicly allocated array (via malloc) of numbers (called "double** metrix") and I need to get the right values and send them to the other function.

I can print the value rightly by using printf("%d", metrix[1][1]) but when I try something like double number; number = metrix[1][1] I get random number (probably randomly selected part of memory?).

How to use this right to get the value I need? Thank you for any help and sorry for my english.

12
  • 2
    double** metrix and printf("%d", metrix[1][1])...I smell trouble... Commented Nov 24, 2015 at 17:00
  • 1
    why not posting the full code you wrote, so we'll get a better perspective of what you're talking about? Commented Nov 24, 2015 at 17:01
  • 1
    Ideally you want to make a short example representing the issue you have, that way we can help you much more easily. Commented Nov 24, 2015 at 17:04
  • 1
    A minimal example that shows the unwanted behaviour is needed here... Commented Nov 24, 2015 at 17:07
  • 3
    As a start: %d stands for decimal integer, not double. What you want is %f Commented Nov 24, 2015 at 17:09

2 Answers 2

1

If you use malloc function, it only allocates a block of size bytes of memory, but the content of the newly allocated block of memory is not initialized, remaining with indeterminate values.

And if you want to print a double value, please use "%f" instead "%d"

Sign up to request clarification or add additional context in comments.

Comments

0

%d stands for decimal integer, not double. What you want is %f which means (fixed) floating point

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.