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 8243181
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 7, 20262026-06-07T21:25:41+00:00 2026-06-07T21:25:41+00:00

Is while (k >= 0 && arr[k] > 0) safe? It loop when k

  • 0

Is

while (k >= 0 && arr[k] > 0) 

safe?

It loop when k in range and arr[k] > 0. But I don’t know if this is a good practice of coding. I know that if we do this

while (arr[k] > 0 && k >= 0) 

it would be a disaster.

  • 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-07T21:25:43+00:00Added an answer on June 7, 2026 at 9:25 pm

    It is safe in the fact that && short circuits. If k is less than zero, it won’t index into arr with it.

    It might not be safe in that the body of your while loop might not decrement k correctly, leading to an infinite loop. Or it might not be safe if k is beyond arr‘s bounds.

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

Sidebar

Related Questions

While writing code in a file that would comprise of PHP, HTML, CSS &
While trying to compile an LLVM IR, like this llc main.ll -o main.s &&
// Main message loop MSG msg; ZeroMemory( &msg, sizeof( msg ) ); while(msg.message!=WM_QUIT) {
Why does this work well: cout << foo; While this doesn't? (&cout)->operator<<(foo); It works
I want to apply a while loop and have written that while (a!=-1) ;
I found this merge sort function but i dont know how to use it.
While solving exercises from the K&R C book, I stumbled upon the exercise 2.1.
while working on osCommerce-3 i got the table structure for category & categories_description as
I get an exception while executing following piece of code bool FieldValueMessage::Get(const std::string &field,
In C++, void somefunction(int) passes a value, while void somefunction(int&) passes a reference. In

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.