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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 18, 20262026-06-18T05:04:13+00:00 2026-06-18T05:04:13+00:00

My compiler: Dev C++ 5.3.0.3 TDM-GCC 4.6.1 64-bit My OS: Windows 7, 64bits My

  • 0

My compiler: Dev C++ 5.3.0.3 TDM-GCC 4.6.1 64-bit
My OS: Windows 7, 64bits

My C Code:

# include "stdio.h"
# include "string.h"

# define MAX (501)

int main() {
    char
        text[MAX]="";

    int i;

    i=0;
    printf("%d\n",strlen(text));        /* 0 */
    printf("%d\n",(strlen(text)-1));    /* -1 */
    if ( i<= (strlen(text)-1) ) printf("haha"); /* haha */

    return 0;
}

My question: Why “haha” is printed?! ( 0>-1 ?!!!)
Thanks for your help!

  • 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-18T05:04:14+00:00Added an answer on June 18, 2026 at 5:04 am

    strlen returns an unsigned value, and the comparison i < strlen(text) - 1 is performed for unsigned integers, in which 0 is indeed no larger than the other.

    When dealing with unsigned types, it is far easier to reason about if you only use +:

    if (i + 1 <= strlen(text))
    

    Or even better:

    if (i < strlen(text))
    

    It can be a bit tricky to understand the arithmetic promotions and conversions for the built-in types and operators, and it might be worth reading up on those. There are certainly some unexpected situations. A good compiler can be made to warn you when you are comparing signed with unsigned types.

    (If you’re curious why in an expression with both signed and unsigned types both get promoted to unsigned, you may note that the conversion from signed to unsigned is absolutely well defined (via modular arithmetic), while the conversion from unsigned to signed is implementation-defined. I suppose that means that the promotion rules mean that the behaviour of arithmetic operations and comparisons is well-defined, rather than just implementation-defined.)

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

Sidebar

Related Questions

The compiler complains about this code: HashMap<String,int> userName2ind = new HashMap<String,int>(); for (int i=0;
Here is my code: #include <stdio.h> void scan(int* i) { int t=0; char c;
Why does the following code compile with the Dev-C++ compiler and not with Visual
Hello I have this problem with PyQt4-dev-tools that include: * a user interface compiler
I wrote a program in C++/OpenGL (using Dev-C++ compiler) for my calculus 2 class.
I want to install open cv library and i am using Dev c++ compiler.
I try to compile unit with ada-zlib. Package ada-zlib-dev is installed. In code I
So, I'm trying to compile my code, but the compiler keeps complaining that 'mysnake'
I've this following code in C++: //file0.cpp #include file11.cpp #include file22.cpp #include<iostream> #include<conio.h> using
I get the error: C:\dev\ws\springapp\build.xml:81: Unable to find a javac compiler; com.sun.tools.javac.Main is not

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.