C String - placement questions answers
1. What would be the output of the following program?main()
{
char *str[] = {“Frog”,”Do”,”Not”, “Die.”,”They”,”Croak!”};
printf(“%d %d”, sizeof (str), sizeof (str[0]));
}
a) 3 12
b) 2 12
c) 12 3
d) 12 2
View Answer / Hide Answer2. What would be the output of the following program?main()
{
char str1[] = “Hello”;
char str2[] = “Hello”;
if(str1 == str2)
printf(“Equal”);
else
printf(“\nUnequal”);
}
a) Error.
b) Equal.
c) Unequal.
d) None.
View Answer / Hide Answer3. Would the following code give any error on compilation?strcat (string,’!’);
a) Yes.
b) No.
View Answer / Hide Answer4. What will happen if I use this code in my program?
#define TRACE(n) printf("TRACE: %d\n", n)a) Nothing it is good.
b) Code is wrong.
c) Error: macro replacement within a string literal
d) None
View Answer / Hide Answer5. How can I print a '%' character in a printf format string?a) Use “\%”
b) Use “/%”
c) None
d) Use “%%”
View Answer / Hide Answer6. String operation such as strcmp(s, t), strcat(s, t), strcpy(s, t) and strlen(s) heavily rely upona) Presence of any escape sequence
b) Presence of NULL character
c) Presence of new-line character
d) None of the mentioned
View Answer / Hide Answer7. What would be the output of the following code?main()
{
Printf(“%c”,”abcdefghijklmn[4]”);
}
a) d.
b) e.
c) abcdefgh.
d) None
View Answer / Hide Answer8. What would be the output of the following program?main()
{
printf (5+“program”);
}
a) ram
b) gram
c) am
d) None
View Answer / Hide Answer9. In the following program which functions would get called?main()
{
char str1[] = “Keep me clean ”;
char str2[40] ;
strcpy(str2,str1);
printf(“n%s”, str2);
}
strcpy(char *t, char *s)
{
while(*s)
{
*t = *s;
t++;
s++;
}
*t =”\0”;
}
a) The library defined strcpy()
b) The user defined strcpy()
c) Both
d) None.
View Answer / Hide Answer10. What is the difference in the following declaration? char *p = “Sundaram”;
char a[] =”Sundaram”;
a) Both are same
b) First pointer initialization with string and other array initialization with string
c) First pointer initialized to point to string constant and other array initialization with string
d) None
View Answer / Hide Answer11. Is the following program correct?main()
{
Char *str1 = “Union”;
Char *str2 = “Minister”;
Char *str3;
str3 = strcat(str1, str2);
Printf(“\n%s”, str3);
}
a) Print “Union Minister”
b) Garbage value
c) Print “UnionMinster”
d) Error
View Answer / Hide Answer12. What would be the output of the following program.main()
{
Char str[7] = “Strings”;
printf(“%s”, str);
}
a) Strings
b) Error
c) Cannot predict
d) None
View Answer / Hide Answer13. What is the output of the following program?void main()
{
printf("IMEIMEMYSELF"+9);
}
a) IMEI.
b) MYSELF.
c) SELF
d) None
View Answer / Hide Answer14. If the two strings are identical, then strcmp() function returns? a) 0
b) 1
c) -1
d) None
View Answer / Hide Answer15. What would be the output of the following programmain()
{
char ch =’A’;
printf(“%d %d”, sizeof(ch), sizeof(‘A’));
}
a) 2 1
b) 1 1
c) 2 2
d) 1 2
View Answer / Hide Answer16. What would be the output of the following program?main()
{
printf(“%d %d %d”, sizeof(‘3’), sizeof(“3”), sizeof(3));
}
a) 1 1 1
b) 2 2 2
c) 1 2 3
d) 1 2 2
View Answer / Hide Answer17. Which one of the following functions returns the string representation from a pointer to a time_t value? a) gettime().
b) seektime().
c) ctime().
d) None
View Answer / Hide Answer18. Consider the declarationStatic char hello[] = “hello”;
The output of printf(“%s\n”, hello);
Will be the same as that of
a) Puts(hello).
b) Puts(“hello”).
c) Puts(“hello\n”).
d) Puts(“%s\n”, “hello”).
View Answer / Hide Answer19. The following programmain()
{
static char a[3][4] = {“abcd”, “mnop”,”fghi”};
putchar(**a);
}
a) Will not compile successfully
b) Report error at run time
c) Print garbege
d) None
View Answer / Hide Answer20. A string that is a formal parameter can be declared a) An array with empty braces
b) A pointer to character
c) A pointer to a character
d) None
View Answer / Hide Answer