What will be the result of the following program?
main()
{
char p[]="String";
int x=0;
if(p=="String")
{
printf("Pass 1");
if(p[sizeof(p)-2]=='g')
printf("Pass 2");
else
printf("Fail 2");
}
else
{
printf("Fail 1");
if(p[sizeof(p)-2]=='g')
printf("Pass 2");
else
printf("Fail 2");
}
}
a) Pass 1, Pass 2
b) Fail 1, Fail 2
c) Pass 1, Fail 2
d) Fail 1, Pass 2
e) syntax error during compilation
Answer Posted / vikram
b)fail1,fail2
bcoz whenever we compare strings,we use strcmp()
function,hence the condition in if() will not be true,
the control will go into else part and will print fail1,then
size of array p is 6 and sizeof(p)-2 results to 4 and hence
p[4]=='n'which again makes the condition in the if()
false,hence fail2 in else part will be printed.
thnx
| Is This Answer Correct ? | 1 Yes | 1 No |
Post New Answer View All Answers
Explain what is wrong with this program statement?
What is difference between class and structure?
PROGRAM TO WRITE CONTENTS OF 1 FILE IN REVERSE TO ANOTHER FILE,PROGRAM TO COPY 1 FILE TO ANOTHER BY SPECIFYING FILE NAMES AS COMMAND LINE
In C programming, what command or code can be used to determine if a number of odd or even?
What is variable initialization and why is it important?
What is %d used for?
which is an algorithm for sorting in a growing Lexicographic order
which of the following is allowed in a "C" arithematic instruction a) [] b) {} c) () d) none of the above
Write a code to generate a series where the next element is the sum of last k terms.
What is typedef?
Are there constructors in c?
What is #include stdio h and #include conio h?
How can a string be converted to a number?
An integer that indentifies the position of a data item in a sequence of data items a) value b) number c) index d) all of the above
Using functions, write a program that multiplies two arrays. Use the following functions: - Function ReadArray - Function MultiplyArrays - Function DisplayArrays