• C

Problem in finding output of a program

What will be the output of this program, please explain


#include<stdio.h>
#include<string.h>

int main()
{
    static char s[] = "Hello!";
    printf("%d\n", *(s+strlen(s)));
    return 0;
}

Open in new window

Sukesh ShuklaAsked:
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

phoffricCommented:
This self-study or homework assignment is quite involved.
>> What will be the output of this program?
When you run the program what output did you get?

>> strlen(s)
What does this mean? What does this expression return? What is its data type?
(If you do not know, then modify your program to print out this value.
http://www.cplusplus.com/reference/cstring/strlen/?kw=strlen

>> s + strlen(s)
What does this mean? What does this expression return? What is the data type of s?
What is the data type of s + strlen(s) ?
(If you do not know what value is returned, then modify your program to print out this value.
https://www.cs.umd.edu/class/sum2003/cmsc311/Notes/BitOp/pointer.html

>> *(s+strlen(s))
What does the * operator mean in this expression?
http://boredzo.org/pointers/
http://www.cplusplus.com/doc/tutorial/pointers/
0

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
Sukesh ShuklaAuthor Commented:
I've requested that this question be deleted for the following reason:

Doubt cleared
0
phoffricCommented:
If my questions, tips, and suggestions, to guide the author, and associated learning links, helped the author to say "doubt cleared", then don't you think my post should be accepted. BTW, in the future, you are free to ask follow up questions if you have more specific issues. That may help speed up your learning process.
0
Sukesh ShuklaAuthor Commented:
I've requested that this question be deleted for the following reason:

complete
0
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
C

From novice to tech pro — start learning today.

Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.