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


Please Help Members By Posting Answers For Below Questions

What is a null string in c?

588


Explain a pre-processor and its advantages.

633


write a program to create a sparse matrix using dynamic memory allocation.

4373


Write a program to print all permutations of a given string.

642


what do u mean by Direct access files? then can u explain about Direct Access Files?

1640






What are pointers? What are stacks and queues?

577


What is modifier & how many types of modifiers available in c?

612


What is identifier in c?

543


What is a nested loop?

651


void main(){ int a; a=1; while(a-->=1) while(a-->=0); printf("%d",a); }

1257


Can math operations be performed on a void pointer?

585


What are reserved words?

654


What is the difference between a free-standing and a hosted environment?

640


Explain what are the __date__ and __time__ preprocessor commands?

594


how many key words availabel in c a) 28 b) 31 c) 32

633