Question

why is correct the output of this code? #include <stdio.h> int main( void ) { char...

why is correct the output of this code?

#include <stdio.h>

int main( void ) {
char val[] = "one";
if (val[1] = 'o')
   printf("correct");
else
   printf("incorrect");
}
0 0
Add a comment Improve this question Transcribed image text
Answer #1
#include <stdio.h>

int main( void ) {
char val[] = "one";
//In C language indexing starts from 0
//So, val[1] is 'o'
//But, if we see the condition of if statement it is equals (=) 
// not a condition operator.
//So, this condition always true
//So, it prints "correct"
if (val[1] = 'o')
   printf("correct");
else
   printf("incorrect");
}

Note: : Follow the comments Follow the com

Please upvote the solution if it helped. Thanks!

Add a comment
Know the answer?
Add Answer to:
why is correct the output of this code? #include <stdio.h> int main( void ) { char...
Your Answer:

Post as a guest

Your Name:

What's your source?

Earn Coins

Coins can be redeemed for fabulous gifts.

Not the answer you're looking for? Ask your own homework help question. Our experts will answer your question WITHIN MINUTES for Free.
Similar Homework Help Questions
ADVERTISEMENT
Free Homework Help App
Download From Google Play
Scan Your Homework
to Get Instant Free Answers
Need Online Homework Help?
Ask a Question
Get Answers For Free
Most questions answered within 3 hours.
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT