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
What is %lu in c?
Write a program to check whether a number is prime or not using c?
What is the use of #define preprocessor in c?
What is the use of void pointer and null pointer in c language?
What are different types of variables in c?
Explain is it better to use a pointer to navigate an array of values, or is it better to use a subscripted array name?
Is c language still used?
I heard that you have to include stdio.h before calling printf. Why?
WRITE A CODE IN C TO SEARCH A FILE FROM NOTEPAD FILE.
What is return type in c?
Can you add pointers together? Why would you?
can we change the default calling convention in c if yes than how.........?
7-Given an index k, return the kth row of the Pascal's triangle. For example, when k = 3, the row is [1,3,3,1]. For reference look at the following standard pascal’s triangle.
Given an array of 1s and 0s arrange the 1s together and 0s together in a single scan of the array. Optimize the boundary conditions?
Given two strings S1 and S2. Delete from S2 all those characters which occur in S1 also and finally create a clean S2 with the relevant characters deleted.