# C | Operators | Question 27

• Difficulty Level : Easy
• Last Updated : 23 Aug, 2019

 `#include ` `#include ` `int` `top=0; ` `int` `fun1() ` `{ ` `    ``char` `a[]= {``'a'``,``'b'``,``'c'``,``'('``,``'d'``}; ` `    ``return` `a[top++]; ` `} ` `int` `main() ` `{ ` `    ``char` `b; ` `    ``char` `ch2; ` `    ``int` `i = 0; ` `    ``while` `(ch2 = fun1() != ``'('``) ` `    ``{ ` `        ``b[i++] = ch2; ` `    ``} ` `    ``printf``(``"%s"``,b); ` `    ``return` `0; ` `}`

(A) abc(
(B) abc
(C) 3 special characters with ASCII value 1
(D) Empty String

Explanation: Precedence of ‘!=’ is higher than ‘=’. So the expression “ch2 = fun1() != ‘(‘” is treated as “ch2 = (fun1() != ‘(‘ )”. So result of “fun1() != ‘(‘ ” is assigned to ch2. The result is 1 for first three characters. Smile character has ASCII value 1. Since the condition is true for first three characters, you get three smilies.

If we, put a bracket in while statement, we get “abc”.

 `#include ` `#include ` `int` `top=0; ` `int` `fun1() ` `{ ` `    ``char` `a[]= {``'a'``,``'b'``,``'c'``,``'('``,``'d'``}; ` `    ``return` `a[top++]; ` `} ` `int` `main() ` `{ ` `    ``char` `b; ` `    ``char` `ch2; ` `    ``int` `i=0; ` `    ``while``((ch2 = fun1()) != ``'('``) ` `    ``{ ` `        ``b[i++] = ch2; ` `    ``} ` `    ``b[i] = ``'\0'``; ` `    ``printf``(``"%s"``,b); ` `    ``return` `0; ` `} `

This modified program prints “abc”

Quiz of this Question

My Personal Notes arrow_drop_up
Recommended Articles
Page :