Strings In C Programming Interview Exam Questions Answers For Engineering Graduates
http://ingenuitydias.blogspot.com/2015/07/strings-in-c-programming-interview-exam.html
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
ANSWER: D
2.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.
ANSWER: C
3.Would the following code give any error on compilation?
strcat (string,’!’);
a) Yes.
b) No.
ANSWER: A
4.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
ANSWER: C
5.How can I print a '%' character in a printf format string?
a) Use “\%”
b) Use “/%”
c) None
d) Use “%%”
ANSWER: D
6.String operation such as strcmp(s, t), strcat(s, t), strcpy(s, t) and strlen(s) heavily rely upon
a) Presence of any escape sequence
b) Presence of NULL character
c) Presence of new-line character
d) None of the mentioned
ANSWER: B
7.What would be the output of the following code?
main()
{
Printf(“%c”,”abcdefghijklmn[4]”);
}
a) d.
b) e.
c) abcdefgh.
d) None
ANSWER: B
8.What would be the output of the following program?
main()
{
printf (5+“program”);
}
a) ram
b) gram
c) am
d) None
ANSWER: C
9.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.
ANSWER: B
10.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
ANSWER: C
11.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
ANSWER: B
12.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
ANSWER: C
13.What is the output of the following program?
void main()
{
printf("IMEIMEMYSELF"+9);
}
a) IMEI.
b) MYSELF.
c) SELF
d) None
ANSWER: C
14.If the two strings are identical, then strcmp() function returns?
a) 0
b) 1
c) -1
d) None
ANSWER: A
15.What would be the output of the following program
main()
{
char ch =’A’;
printf(“%d %d”, sizeof(ch), sizeof(‘A’));
}
a) 2 1
b) 1 1
c) 2 2
d) 1 2
ANSWER: D
16.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
ANSWER: B
17.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
ANSWER: C
18.Consider the declaration
Static 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”).
ANSWER: A, B, D
19.The following program
main()
{
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
ANSWER: D
20.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
ANSWER: A, B
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
ANSWER: D
2.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.
ANSWER: C
3.Would the following code give any error on compilation?
strcat (string,’!’);
a) Yes.
b) No.
ANSWER: A
4.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
ANSWER: C
5.How can I print a '%' character in a printf format string?
a) Use “\%”
b) Use “/%”
c) None
d) Use “%%”
ANSWER: D
6.String operation such as strcmp(s, t), strcat(s, t), strcpy(s, t) and strlen(s) heavily rely upon
a) Presence of any escape sequence
b) Presence of NULL character
c) Presence of new-line character
d) None of the mentioned
ANSWER: B
7.What would be the output of the following code?
main()
{
Printf(“%c”,”abcdefghijklmn[4]”);
}
a) d.
b) e.
c) abcdefgh.
d) None
ANSWER: B
8.What would be the output of the following program?
main()
{
printf (5+“program”);
}
a) ram
b) gram
c) am
d) None
ANSWER: C
9.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.
ANSWER: B
10.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
ANSWER: C
11.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
ANSWER: B
12.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
ANSWER: C
13.What is the output of the following program?
void main()
{
printf("IMEIMEMYSELF"+9);
}
a) IMEI.
b) MYSELF.
c) SELF
d) None
ANSWER: C
14.If the two strings are identical, then strcmp() function returns?
a) 0
b) 1
c) -1
d) None
ANSWER: A
15.What would be the output of the following program
main()
{
char ch =’A’;
printf(“%d %d”, sizeof(ch), sizeof(‘A’));
}
a) 2 1
b) 1 1
c) 2 2
d) 1 2
ANSWER: D
16.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
ANSWER: B
17.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
ANSWER: C
18.Consider the declaration
Static 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”).
ANSWER: A, B, D
19.The following program
main()
{
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
ANSWER: D
20.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
ANSWER: A, B
Very Very useful for people searching for Job. Good Collection.
ReplyDelete