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 / shruti
syntax error during compilation..
we cannot compare strings using if(p == "string")
so will not work..
NOTE:
while comparing string otherwise also we use 'string'
(string in single quotes ' ' not " ")..
Is This Answer Correct ? | 0 Yes | 2 No |
Post New Answer View All Answers
What is a null string in c?
Explain a pre-processor and its advantages.
write a program to create a sparse matrix using dynamic memory allocation.
Write a program to print all permutations of a given string.
what do u mean by Direct access files? then can u explain about Direct Access Files?
What are pointers? What are stacks and queues?
What is modifier & how many types of modifiers available in c?
What is identifier in c?
What is a nested loop?
void main(){ int a; a=1; while(a-->=1) while(a-->=0); printf("%d",a); }
Can math operations be performed on a void pointer?
What are reserved words?
What is the difference between a free-standing and a hosted environment?
Explain what are the __date__ and __time__ preprocessor commands?
how many key words availabel in c a) 28 b) 31 c) 32