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
Draw a diagram showing how the operating system relates to users, application programs, and the computer hardware ?
Write a program which returns the first non repetitive character in the string?
Are local variables initialized to zero by default in c?
Write a program to produce the following output: 1 2 3 4 5 6 7 8 9 10
int main() { Int n=20,i; For(i=0;i<=n;i--) { Printf(“-“); Return 0;
What is difference between && and & in c?
What is volatile variable how do you declare it?
What is the difference between %d and %i?
What does typedef struct mean?
What is chain pointer in c?
Explain what will be the outcome of the following conditional statement if the value of variable s is 10?
What is wild pointer in c with example?
What are dangling pointers? How are dangling pointers different from memory leaks?
What does a function declared as pascal do differently?
What is array of structure in c programming?