Home » Aptitude Questions and Answers » C Aptitude Questions and Answers

C Strings - Aptitude Questions & Answers



C programming String Aptitude Questions and Answers: In this section you will find C Aptitude Questions and Answers on Strings, String is the set of characters and String related Aptitude Questions and Answers you will find here.

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;
}
  1. 0
  2. 1
  3. -1
  4. Error

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;
}
  1. Hello
  2. Error
  3. No Output
  4. Null



3) What will be the output of following program ?
#include <stdio.h>
int main()
{
	char str[8]="IncludeHelp";
	printf("%s",str);
	return 0;
}
  1. IncludeHelp
  2. IncludeH
  3. Error
  4. No Output

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;
}
  1. IncludeHelp.Com
  2. udeHelp
  3. Error
  4. IncludeHelp4



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;
}
  1. HelloFriends
    HelloFriends
  2. Hello%s%dFriends
    Hello%s%dFriends
  3. Hello(null)0Friends
    Hello%s%dFriends
  4. Garbage Value

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;
}
  1. value is =%d
  2. value is =%c
  3. value is =55
  4. value is =7

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;
}
  1. \0IncludeHelpTRUE
  2. \0IncludeHelpFALSE
  3. Error
  4. FALSE



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;
}
  1. Hello...Friends
  2. Hello...Enemies
  3. ...Friends
  4. ...Enemies

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;
}
  1. Inclu
  2. IncluGARBAGE_VALUE
  3. Error
  4. IncludeHelp



11) What will be the output of following program ?
#include <stdio.h>
#include <string.h>
int main()
{
	char str[50]="IncludeHelp";
	printf("%d...%d",strlen(str),sizeof(str));
	return 0;
}
  1. 50...50
  2. 11...50
  3. 11...11
  4. 50...11

12) What will be the output of following program ?
#include <stdio.h>
int main()
{
	char *str="IncludeHelp";
	while(*str)
		printf("%s\n",str++);
	return 0;
}
  1. IncludeHelp
    IncludeHel
    IncludeHe
    ..
    I
  2. IncludeHelp
    ncludeHelp
    cludeHelp
    ..
    P
  3. ERROR
  4. IncludeHelp



13) What will be the output of following program ?
#include <stdio.h>
#define string char*
int main()
{
	string myName="IncludeHelp";
	printf("My name is =%s",myName);
	return 0;
}
  1. IncludeHelp
  2. Error
  3. char*
  4. myName

14) What will be the output of following program ?
#include <stdio.h>
#include <string.h>
int main()
{
	printf("%d...%d",sizeof("Hello"),strlen("Hello"));
	return 0;
}
  1. 5...5
  2. 6...6
  3. 5...6
  4. 6...5

15) What will be the output of following program ?
#include <stdio.h>
#include <string.h>
int main(){
	char str[]="Ihelp";

	while(str+strlen(str))
		printf("*");
	return 0;
}
  1. ERROR
  2. No output
  3. ***... infinite times
  4. *






Was this page helpful? YES NO

Are you a blogger? Join our Blogging forum.



Comments and Discussions


We are using Google to publish ads on our website; Google has its own privacy policies. They may save log, cookies on your system. Google may also collect information of your system like IP address, region, city, country. For more details please go through the Google’s privacy policy.