Program Discussion :: Basics
307 / 279
Write a program using sizeof and strlen.
Answer:
#include
#include
int main()
{
char str[50];
printf("\nEnter a string: ");
scanf("%s",str);
printf("\nSize of the string is: %d",sizeof(str)); //sizeof() operator gives the size in bytes.
printf("\nLength of the string is: %d",strlen(str)); //strlen() function gives the length of the whole string.
return 0;
}
Asked In ::
Language:
Siddhartha Paul
19 Jun, 2019 2:16 PM
#include<stdio.h>
#include<string.h>
int main()
{
char str[50];
printf("\nEnter a string: ");
scanf("%s",str);
printf("\nSize of the string is: %d",sizeof(str)); //sizeof() operator gives the size in bytes.
printf("\nLength of the string is: %d",strlen(str)); //strlen() function gives the length of the whole string.
return 0;
}