English Deutsch Français Italiano Español Português 繁體中文 Bahasa Indonesia Tiếng Việt ภาษาไทย
All categories

Which of the following is a correct call to strlen?
Given:
char MyString[1024];
int Max=0;
a. Max=strlen(MyString);
b. strlen(MyString,Max)
c. strlen(MyString,&Max);
d. strlen(Max,MyString);
e. Max=strlen(*MyString);

2007-04-03 13:26:50 · 3 answers · asked by nig n 1 in Computers & Internet Programming & Design

3 answers

Assuming C language, then a) is the correct call. strlen takes a "const char *" and returns an int.

Note that since you never assigned anything to MyString, the output of strlen() will be unpredictable.

2007-04-03 16:14:36 · answer #1 · answered by dvari 3 · 0 0

What language are you using?

You have an array of characters of size 1024 bytes (0 - 1023).

a) is wrong. You cant assign Max var of type int to an array of type char. You would need casting.

b) c) d) - depends what language it is. C doesnt look right. Actually B and D dont look right either.

e) could be right - saying the Max variable is a pointer to the array and you are asking for its string length...

2007-04-03 13:56:15 · answer #2 · answered by Vanderbere 2 · 0 0

In gcc version 3.4.6
a. Max is 0
b. syntax error
c. syntax error
d. syntax error
e. segmentation fault.

2007-04-03 17:03:35 · answer #3 · answered by Vegan 7 · 0 0

fedest.com, questions and answers