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

Strings: Week: 4 Duration: 60 Mins

This document contains 30 multiple choice questions related to strings in C programming. The questions cover topics like string functions, string manipulation, string comparisons, character arrays, and more. Sample programs and their expected outputs are provided for each question to help understand strings and related concepts in C.

Uploaded by

subash
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
62 views

Strings: Week: 4 Duration: 60 Mins

This document contains 30 multiple choice questions related to strings in C programming. The questions cover topics like string functions, string manipulation, string comparisons, character arrays, and more. Sample programs and their expected outputs are provided for each question to help understand strings and related concepts in C.

Uploaded by

subash
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 6

‘C’ & ‘C’ only Sona Placement & Training Cell

4. Strings
Week : 4 Duration : 60 mins

1.Why doesn’t the following statement work?


char str[ ] = “Hello” ;
strcat ( str, ‘!’ ) ;

2.What will the statement, strlen(“Good Morning”); , return?


a) 10 b) 11 c) 12 d) 13

3.What character terminates all character array strings


a) \0 b) . c) END

4.What is the output of the given code?


main()
{ char *cptr,c;
void *vptr,v;
c=10; v=0;
cptr=&c; vptr=&v;
printf(“%c%v”,c,v);
}

5.What is the output of the given code?


main()
{
char *str1=”abcd”;
char str2[]=”abcd”;
printf(“%d %d %d”,sizeof(str1),sizeof(str2),sizeof(“abcd”));
}

6.What is the output of the given code?


main()
{
int k=1;
printf(“%d==1 is “”%s”,k,k==1?”TRUE”:”FALSE”);
}

24
‘C’ & ‘C’ only Sona Placement & Training Cell

7.What is the output of the given code?


void main()
{ char a[]=”12345\0”;
int i=strlen(a);
printf(“here in 3 %d\n”,++i);
}

8.What is the output of the given code?


main()
{ while (strcmp(“some”,”some\0”))
printf(“Strings are not equal\n”);
}

9. What is the output of the given code:


main()
{ char str1[] = {‘s’,’o’,’m’,’e’};
char str2[] = {‘s’,’o’,’m’,’e’,’\0’};
while (strcmp(str1,str2))
printf(“Strings are not equal\n”);
}

10.What is the output of the given code?


main()
{ char *p=”GOOD”;
char a[ ]=”GOOD”;
printf(“\n sizeof(p) = %d, sizeof(*p) = %d, strlen(p) = %d”,
sizeof(p), sizeof(*p), strlen(p));
printf(“\n sizeof(a) = %d, strlen(a) = %d”, sizeof(a), strlen(a));
}

11. char inputString[100] = {0};


To get string input from the keyboard which one of the following is better?
a) gets(inputString) b) fgets(inputString, sizeof(inputString), fp)

12.Which version do you prefer of the following two


a) printf(“%s”,str); // or the more curt one b) printf(str);

13.Which of the Following is not defined in string.h?


a) strspn() b) strerror() c) memchr() d) strod()

25
‘C’ & ‘C’ only Sona Placement & Training Cell

14. Look at the Code:


#include<string.h>
void main()
{ char s1[]=”abcd”;
char s2[10];
char s3[]=”efgh”;
int i;
clrscr();
i=strcmp(strcat(s3,strcpy(s2,s1))strcat(s3,”abcd”));
printf(“%d”,i);
}
What will be the output?
a) No output b) A Non Integer c) 0 d) Garbage

15. How will u print TATA alone from TATA POWER using string copy
and concate commands in C?

16.sscanf is used for ?

17.What does the statement strcat(S2,S1) do?

18.What is a string?
a) array of characters without /0; b) array of characters ending with /0;

19. What will be the output of the following program


char *someFun()
{ char *temp = “string constant”;
return temp; }
int main()
{ puts(someFun()); }

20.What will be the output of the following program


main()
{ char s[]={‘1’,’2’,’3’,0,’1’,’2’,’3’};
printf(“%s”,s);
}
a) 123 b) 123123 c) 1230123 d) error

26
‘C’ & ‘C’ only Sona Placement & Training Cell

4. Assignment

21. What will be the output of the following program?


main()
{ char *p=”Caritor”;
*++p;
printf(“%s”,p);
*++p;
printf(“%s”,*p);
}

22. How to print “%” symbol in printf?

23. What will be the output of the following program?


main()
{ char str1[]=”HELLO”;
char str2[]=”HELLO”;
if(str1==str2)
printf(“EQUAL”);
else
printf(“NOT EQUAL”);
}

24. What will be the output of the following program?


#include<stdio.h>
void main(int arg c)
{ char a[]=abcdefghijklmnopqrstuvwxyz;
char *p=a;
printf(%d,strlen(p));
p+=10;
printf(%d,strlen(a));
}
a) 26 26 b) 26 16 c) compilation error d) 16 26

25.Output of following will be


#include<stdio.h>
main()
{ char p=”A”;
int q=65;
switch(1)

27
‘C’ & ‘C’ only Sona Placement & Training Cell

{ case 1:
printf(“%dand %c”,p.,q);
printf(“%cand%d”,p,q); }
}
a) A AND 65 b) 65 AND A
c) A and 65 d) 65 and A
65 and A A and 65

26. Output of following will be


# include<stdio.h>
#include<math.h>
main()
{ unsigned short p=pow(2,15)+pow(2,9)+pow(2,6)+poe(2,0); //33345
char c;
c=p;
printf(“%c/n”,c);
}
a) 33345 b) 45 c) A d) none

27. What will the below program do?


String Concatenate(Char *s1,Char *s2)
{ Char buf[1000];
Buf[0]=null;
Strcat(buf,s1);
Strcat(buf,s2);
Return buf;
}
a) should not return pointer to local variable. b) Nothing Wrong in this function.
c) It don’t work if length exceeds 1000 char. d) Error in this code.

28. What is the output of the following code?


main()
{
printf(“Hello %d”,printf(“QUARK test? “));
}
a) Compile time error. b) Hello QUARK test? c) Run time error.
d) None of the above. e) Quark Test ?Hello.

28
‘C’ & ‘C’ only Sona Placement & Training Cell

29. What shall be the output of the following code?


main()
{ char i = ‘a’;
printf(“%c \t %c \t”, i ,(++i)); }
a) a b b) Compile time error c) b b
d) a a e) 65 66

30. What shall be the output of the following code?


main()
{
char str1[]=”Hello”;
char str2[]=”Hello”;
if(str1= =str2&& (*(str1+6)= =*(str2+6)))
printf(“\n Equal”);
else
printf(“\n unequal”);
}
a) Equal b) Unequal c) Compilation error.
d) Runtime error. e) None of the above.

29

You might also like