What is the strlen of a? | Sololearn: Learn to code for FREE!
Neuer Kurs! Jeder Programmierer sollte generative KI lernen!
Kostenlose Lektion ausprobieren
+ 16

What is the strlen of a?

#include<stdio.h> #include<string.h> int main (void) { char a[20]; int x; x = strlen(a); printf("%d",x); return 0; }

26th Jul 2019, 5:58 PM
Aung Thiha
Aung Thiha - avatar
9 Antworten
+ 6
It depends on where the first null happens to be in memory at runtime. Don't expect it to be the same in every run. And you should understand that strlen(a) won't necessarily stop counting at 20.
27th Jul 2019, 5:00 PM
Brian - avatar
+ 14
~ swim ~ yes. It depends on the ide, output was changed
27th Jul 2019, 4:54 PM
Aung Thiha
Aung Thiha - avatar
+ 10
Bandi yes. You're right. And solve it­čśé
27th Jul 2019, 4:50 PM
Aung Thiha
Aung Thiha - avatar
+ 6
Yes the output is different in different compilers ~ swim ~
27th Jul 2019, 5:03 PM
+ 3
Try this ­čśé­čśé­čśé https://code.sololearn.com/coap1Y62P1s5/?ref=app
28th Jul 2019, 10:44 AM
Paolo De Nictolis
Paolo De Nictolis - avatar
+ 2
The answer may be " 3 "
27th Jul 2019, 4:47 PM
+ 2
strlen is different to sizeof, so cannot be predicted here due to uninitialised array.
27th Jul 2019, 11:15 PM
Sonic - avatar
+ 2
You have assigned the value of string length to a variable "x" but you haven't actually inputted anything in the character variable "a". And because there is nothing specific entered by you in the variable there is some garbage or irrational value stored in a and that is why when you print "x" which should return the string length of your character instead of returning what you think it would, it will return a not so specific and correct value because there is nothing inputted inside it
28th Jul 2019, 10:23 AM
Rohan Dhar
Rohan Dhar - avatar
+ 1
You would get a garbage value because 'a' is a NULL string.
27th Jul 2019, 12:05 AM
haydenki - avatar