C Programming - Strings - Discussion
Discussion Forum : Strings - Find Output of Program (Q.No. 12)
12.
What will be the output of the program ?
#include<stdio.h>
#include<string.h>
int main()
{
static char s[] = "Hello!";
printf("%d\n", *(s+strlen(s)));
return 0;
}
Discussion:
38 comments Page 4 of 4.
Shaurabh Suman said:
8 years ago
Here,
strlen(s)= 6.
So,
*(s+ strlen(s)) = *(s + 6) = s[6].
But here,
s[6] = '\0'.
So , the ASCII value of '\0' is zero.
Ans - 0.
strlen(s)= 6.
So,
*(s+ strlen(s)) = *(s + 6) = s[6].
But here,
s[6] = '\0'.
So , the ASCII value of '\0' is zero.
Ans - 0.
(3)
Vilas said:
8 years ago
As pointer s, points to the (s+6) th position. There mean null space (\0). And static char keep default value as 0. If the variable is not initialized.
So the answer 0.
So the answer 0.
Buela said:
8 years ago
Thanks @Musaraf.
Mala said:
7 years ago
Thanks to all for explaining this.
(1)
Jibon said:
6 years ago
Thanks @Dipankar.
Musthak Rahaman said:
6 years ago
In this for strlen we have to count how many elements present in the given string value...and *(s+strlen(s))becomes *(s+6)it is nothing but s[6] but in declared string variable we have 5 positions hence s[6] must be "\0" so the answer is 0.
(9)
Kalyan said:
6 years ago
The answer is 6 in GCC compiler.
(2)
Shah said:
4 years ago
* (s+6) and array start from 0, so the last 6th char is NULL and ASCII value of NULL is zero (0) So it will return 0 (zero).
(12)
Post your comments here:
Quick links
Quantitative Aptitude
Verbal (English)
Reasoning
Programming
Interview
Placement Papers