Home > Backend Development > C++ > Why Does \'25\' 1 Output \'5\' in C ?

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

Patricia Arquette
Release: 2024-11-01 14:38:02
Original
697 people have browsed it

Why Does

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

The code snippet

#include <iostream><br>int main()<br>{</p>
<div class="code" style="position:relative; padding:0px; margin:0px;"><pre class="brush:php;toolbar:false">std::cout << "25"+1;
return 0;
Copy after login

}

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!

source:php.cn
Statement of this Website
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
Latest Articles by Author
Popular Recommendations
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template