0% found this document useful (0 votes)
208 views

C Programming Tutorial - Strings

This document contains 10 questions about C programs involving strings. The questions test various string functions like strcmp(), strcpy(), strlen(), printf() and their behavior when used with strings of different lengths, contents and data types. The correct output is to be determined for each program.

Uploaded by

Raji Pillai
Copyright
© © All Rights Reserved
Available Formats
Download as DOC, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
208 views

C Programming Tutorial - Strings

This document contains 10 questions about C programs involving strings. The questions test various string functions like strcmp(), strcpy(), strlen(), printf() and their behavior when used with strings of different lengths, contents and data types. The correct output is to be determined for each program.

Uploaded by

Raji Pillai
Copyright
© © All Rights Reserved
Available Formats
Download as DOC, PDF, TXT or read online on Scribd
You are on page 1/ 3

TUTORIAL QUESTIONS ON STRINGS

1) What will be the output of following program ?

#include <stdio.h>
#include <string.h>
int main()
{
int val=0;
char str[]="IncludeHelp.Com";

val=strcmp(str,"includehelp.com");
printf("%d",val);
return 0;
}

2) What will be the output of following program ?

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

int main()
{
char str[];
strcpy(str,"Hello");
printf("%s",str);
return 0;
}

3) What will be the output of following program ?

#include <stdio.h>
int main()
{
char str[8]="IncludeHelp";
printf("%s",str);
return 0;
}

4) What will be the output of following program ?

#include <stdio.h>
#include <string.h>
int main()
{
char str1[]="IncludeHelp",str2[]=".Com";
printf("%s",str1+strlen(str2));
return 0;
}

5) What will be the output of following program ?


#include <stdio.h>
int main()
{
char str[]="Hello%s%dFriends";
printf(str);
printf("\n");
printf("%s",str);
return 0;
}

6) What will be the output of following program ?

#include <stdio.h>
int main()
{
int i;
char str[]="IncludeHelp";
for(i=0;str[i]!='\0';i++)
{
putchar(str[i]);
putchar('*');
}
return 0;
}

7) What will be the output of following program ?

#include <stdio.h>
int main()
{
char str[]="value is =%d";
int a='7';
str[11]='c';
printf(str,a);
return 0;
}

8) What will be the output of following program ?

#include <stdio.h>
int main()
{
char result,str[]="\0IncludeHelp";
result=printf("%s",str);
if(result)
printf("TRUE");
else
printf("FALSE");
return 0;
}
9) What will be the output of following program ?

#include <stdio.h>
#include <string.h>
int main()
{
if( printf("Hello") == strlen("Hello") )
printf("...Friends");
else
printf("...Enemies");
return 0;
}

10) What will be the output of following program ?

#include <stdio.h>
#include <string.h>
int main()
{
char s1[]="IncludeHelp";
char s2[10];

strncpy(s2,s1,5);
printf("%s",s2);
return 0;
}

You might also like