[Updated] Goldman Sachs Aptitude Test Questions and Answers
Practice List of TCS Digital Coding Questions !!!
Take 50+ FREE!! Online Data Interpretation Mock test to crack any Exams.

Program Discussion :: Basics

Home > Programs > 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 :: Syntel Inc.

Post Your Answer Here:

Language:

Post Your Reply Here: