Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8040141
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 5, 20262026-06-05T03:47:56+00:00 2026-06-05T03:47:56+00:00

I have the following code sequential search run perfectly in Visual C++ #include<iostream> using

  • 0

I have the following code sequential search run perfectly in Visual C++

#include<iostream>
using namespace std;

int seqSearch(int list[], int length, int item)
{
    int index = length-1;
    if (index < 0)
        return -1;
    if (list[index] == item)
        return (index);
    else seqSearch(list, index, item);
} // end seqSearch

int main () 
{

    int const length = 10;
    int item;
    int list[10] = { 2, 3, 4, 5, 20, 40, 80, 45, 99, 0};

    cout << "Please enter the value to be searched: ";
    cin>> item;

    if (seqSearch(list, length, item) == -1) cout << "Item not found." << endl;
    else cout <<"Item found at position: " << seqSearch(list, length, item) << " of list *Note: (first index of list start at 0)" << endl;

    system("pause");
    return 0; 
}

But in Dev-C++ it always display result 0, I tried to debug and see index is correct but why it display 0? Why we have this difference between VC++ and Dev-C++?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-05T03:48:01+00:00Added an answer on June 5, 2026 at 3:48 am

    The function int seqSearch has a code path, else seqSearch(list, index, item); that is not returning anything. Changing this to else return seqSearch(list, index, item); should solve the problem.

    Now digging a little deep.

    From n2960 draft:

    § 6.6.3/2

    Flowing off the end of a function is equivalent to a return with no value; this results in undefined behavior in a value-returning function.

    So as per the standard it is an undefined behavior.

    Digging a little deeper:

    • Why is not returning from a non-void function not a compiler error?

    Checking all code path to figure out if all of them return is a difficult operation and implementations are not required to check that.

    • Why is the code functionally working properly in VC++

    This is architecture and calling convention dependent. Try following code:

    #include <iostream>
    
    int fun (int v)
    {
        int a = v;
    }
    
    int main ()
    {
        std::cout << fun(5) << std::endl;
    }
    

    On different compilers the function fun returns either 0 or whatever value is passed to it. Basically it can return value of last evaluated expression.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have following code for opening all files: int ret= open(zFile, flags, mode); posix_fadvise
I have tried the following code using the 2.0 framework and I get an
I have the following C Header/Code Example: Header file struct category_info { int id;
I have code numbers as the following sequential: 1 1.1 1.2 1.3 . .
I have following code.. $query = SELECT quote, author FROM quotes ORDER BY id
I have following code: <?php $select_options = array(); foreach($delivery_options as $option) { $select_options[$option->getDeviceId()] =
I have following code and it returns false for @B LIKE @A comparison in
I have following code $("#in").datepicker({ minDate: 0, onSelect: function (dateText, inst) { dateText =
I have following code if (rs != null) { out.println(result set has got something);
I have following code in the html file: <div class=navbar navbar-fixed-top> <div class=navbar-inner> <div

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.