Home  >  Article  >  Backend Development  >  Why Does \"25\" 1 Output \"5\" in C ?

Why Does \"25\" 1 Output \"5\" in C ?

Patricia Arquette
Patricia ArquetteOriginal
2024-11-01 14:38:02622browse

Why Does

The Unexpected Concatenation of Strings and Numbers in C : Exploring "456" 1

The code snippet

#include <iostream><br>int main()<br>{</p>
<pre class="brush:php;toolbar:false">std::cout << "25"+1;
return 0;

}

poses a perplexing question: why does the expression "25" 1 output "5" instead of an expected "26"? To unravel this mystery, let's delve into the inner workings of this code.

In C , string literals like "25" are not treated as true strings but as character arrays. In the example given, "25" is equivalent to a character array {'2', '5', '

The above is the detailed content of Why Does \"25\" 1 Output \"5\" in C ?. For more information, please follow other related articles on the PHP Chinese website!

Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn