+ 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
12 Answers
+ 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
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
PRAKASH BANDI
PRAKASH BANDI - avatar
+ 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
PRAKASH BANDI
PRAKASH BANDI - avatar
+ 2
strlen is different to sizeof, so cannot be predicted here due to uninitialised array.
27th Jul 2019, 11:15 PM
Sonic
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
haydenki - avatar