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

provide an example of the Group by clause, when would you use this clause

1701


What is header file definition?

563


Explain what is the most efficient way to store flag values?

692


Can you add pointers together? Why would you?

635


How to write a code for reverse of string without using string functions?

1575






Can we declare a function inside a function in c?

574


What does the characters “r” and “w” mean when writing programs that will make use of files?

848


What does the c in ctime mean?

561


Describe newline escape sequence with a sample program?

646


What is the c language function prototype?

642


Write a program, where i have a grid with many cells, how many paths are possible from one point to other desired points.

696


1. Write a function to display the sum of two numbers in the following ways: By using (i) pass by value (ii) pass by address a. function with argument and with return value b. function with argument and without return value c. without argument , with return value d. without argument , without return value Note: Use pass by address.

2329


What happens if you free a pointer twice?

600


What is a keyword?

740


Can you please explain the scope of static variables?

597