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 functions are used for dynamic memory allocation in c language?
any limit on the number of functions that might be present in a C program a) max 35 functions b) max 50 functions c) no limit d) none of the above
What are register variables? What are the advantage of using register variables?
How can I read data from data files with particular formats?
#include main() { int *p, *c, i; i = 5; p = (int*) (malloc(sizeof(i))); printf(" %d",*p); *p = 10; printf(" %d %d",i,*p); c = (int*) calloc(2); printf(" %d ",*c); }
What should malloc(0) do? Return a null pointer or a pointer to 0 bytes?
what is reason of your company position's in india no. 1.
What is the use of function overloading in C?
How can you return multiple values from a function?
PROGRAM TO WRITE CONTENTS OF 1 FILE IN REVERSE TO ANOTHER FILE,PROGRAM TO COPY 1 FILE TO ANOTHER BY SPECIFYING FILE NAMES AS COMMAND LINE
Why doesn't C support function overloading?
Is there a way to switch on strings?
Explain the use of 'auto' keyword
What are the advantages of external class?
What are the characteristics of arrays in c?