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

Draw a diagram showing how the operating system relates to users, application programs, and the computer hardware ?

2338


Write a program which returns the first non repetitive character in the string?

816


Are local variables initialized to zero by default in c?

747


Write a program to produce the following output: 1 2 3 4 5 6 7 8 9 10

15428


int main() { Int n=20,i; For(i=0;i<=n;i--) { Printf(“-“); Return 0;

1354


What is difference between && and & in c?

847


What is volatile variable how do you declare it?

753


What is the difference between %d and %i?

806


What does typedef struct mean?

843


What is chain pointer in c?

773


Explain what will be the outcome of the following conditional statement if the value of variable s is 10?

995


What is wild pointer in c with example?

772


What are dangling pointers? How are dangling pointers different from memory leaks?

907


What does a function declared as pascal do differently?

797


What is array of structure in c programming?

991