×

# Problem in declaring vector,Runtime error

 0 The link to my code is http://ideone.com/mwwBjl Why am i getting runtime error. the above code is solution of question https://www.interviewbit.com/problems/smallest-multiple-with-0-and-1/ Thanks in advance. asked 16 Jul '16, 01:32 3★buffy20 5●1●12 accept rate: 0%

 0 the problem is in your multiple function not in declaration.. if you try to run your main only by commenting your multiple function you will see the output "in main" answered 16 Jul '16, 01:54 619●6 accept rate: 12% on dev c++, I could even see some chk0 printed.chk0 which are before the assignment flag[val]=1 get printed and after that code stops working. (16 Jul '16, 02:48) buffy203★
 0 Your multiple function returns an std::string but you haven't used the return value. Though this is not the reason of the runtime error, still it will give a warning. In line number 16 and 18, you are doing flag[val] = 1, where val = 1 according to your code. However, your vectors are still of size 0, so you are accessing memory out of bounds, which gives you RTE. Have a look at this code of yours. I have removed the RTE, but have not touched your solution: Corrected code answered 16 Jul '16, 05:49 123●5 accept rate: 0% Got it. Thanks a lot. (16 Jul '16, 12:53) buffy203★
 toggle preview community wiki:
Preview

By Email:

Markdown Basics

• *italic* or _italic_
• **bold** or __bold__
• image?![alt text](/path/img.jpg "title")
• numbered list: 1. Foo 2. Bar
• to add a line break simply add two spaces to where you would like the new line to be.
• basic HTML tags are also supported
• mathemetical formulas in Latex between \$ symbol

Question tags:

×525
×231
×73
×6

question asked: 16 Jul '16, 01:32

question was seen: 1,371 times

last updated: 16 Jul '16, 12:53