#include <stdio.h>
int main ()
{
char *ptr = "stackoverflow"
}
Is there any way to find the length of stackoverflow pointed by ptr, as sizeof ptr always gives 4
Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.
Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.
Lost your password? Please enter your email address. You will receive a link and will create a new password via email.
Please briefly explain why you feel this question should be reported.
Please briefly explain why you feel this answer should be reported.
Please briefly explain why you feel this user should be reported.
sizeof()returns the size required by the type. Since the type you pass to sizeof in this case is a pointer, it will return size of the pointer.If you need the size of the data pointed by a pointer you will have to remember it by storing it explicitly.
sizeof()works at compile time. so,sizeof(ptr)willreturn 4 or 8 bytestypically. Instead usestrlen.