Download as doc, pdf, or txt
Download as doc, pdf, or txt
You are on page 1of 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