Форум С++

 

Ответить на сообщение

Вернуться к теме

Вы отвечаете на сообщение:

Автор: GeorgeIV   (17.12.2008 в 09:25)
но почемуто у меня sizeof() всегда показывает 4 со строками, а читал где-то что должен
 размер строки показывать. Надо попробовать другим компилятором,

Дело не в компиляторе, а в понимании.
sizeof(str) выдает размер указателя на строку, а он чаще всего будет 4 байта
а sizeof str должен как раз выдать длину строки.


MSDN:
Yields the size of its operand with respect to the size of type char.

 
sizeof unary-expression
sizeof ( type-name )
 

Remarks
The result of the sizeof operator is of type size_t, an integral type defined in the include file
 STDDEF.H. This operator allows you to avoid specifying machine-dependent data sizes in your
 programs.

The operand to sizeof can be one of the following: 

A type name. To use sizeof with a type name, the name must be enclosed in parentheses.

An expression. When used with an expression, sizeof can be specified with or without the
 parentheses. The expression is not evaluated.


Ваше имя:

Пароль:

Цитировать

Используйте тэги для выделения текста:
Код: [code][/code]
Жирный: [b][/b]
Наклонный: [i][/i]
URL: [url][/url]

Сообщение:

Прикрепить: