You are not logged in. Please login at www.codechef.com to post your questions!

×

end() string doest not have null character?

string s="string"; if(*s.end()=='/0') cout<<"he";

he doesnt come. Doesnt the string store null character in the end?

asked 09 Dec '18, 00:39

galavk's gravatar image

3★galavk
01
accept rate: 0%


The string you're using is an object of the string class (called std::string), it is not null-terminated (<string>). C-style strings on the other hand are null-terminated, they're basically character arrays terminated with a '\0' (<cstring>). For example,

char c[]="string";
assert(c[6]=='\0');

The assert statement will not terminate the program as it evaluates to true.

link

answered 09 Dec '18, 02:32

ankitmaity's gravatar image

2★ankitmaity
254
accept rate: 0%

edited 09 Dec '18, 02:34

toggle preview
Preview

Follow this question

By Email:

Once you sign in you will be able to subscribe for any updates here

By RSS:

Answers

Answers and Comments

Markdown Basics

  • *italic* or _italic_
  • **bold** or __bold__
  • link:[text](http://url.com/ "title")
  • image?![alt text](/path/img.jpg "title")
  • numbered list: 1. Foo 2. Bar
  • to add a line break simply add two spaces to where you would like the new line to be.
  • basic HTML tags are also supported
  • mathemetical formulas in Latex between $ symbol

Question tags:

×1,901
×630
×6

question asked: 09 Dec '18, 00:39

question was seen: 48 times

last updated: 09 Dec '18, 02:34