Like us on Facebook

News: If you feel any problem while posting a topic or Reply - Contact our server team at: +92-341-2825535


Author Topic: The following program fragment int k=-7; printf("%d", 0 < !k);  (Read 387 times)

Offline mechanic

  • Engineer
  • Hero Engineer
  • *****
  • Posts: 2253
    • View Profile
    • Engineering Forum
Advertisement
Question: The following program fragment

int k=-7;
printf("%d", 0 < !k);


Options are:

A. prints 0
B. prints a non-zero value
C. is illegal
D. prints an unpredictable value

Correct answer is:

A. Prints 0


Explanation:

k = - 7, so if 'k' is used as a boolean variable, it will be treated as a true condition. so, !k will be false i.e. 0. so 0 <? !k is actually 0 < 0. which is false. so. 0 will be printed.
« Last Edit: March 08, 2017, 08:44:44 AM by mechanic »

Engineering Forum

Like us on Facebook

 

With Quick-Reply you can write a post when viewing a topic without loading a new page. You can still use bulletin board code and smileys as you would in a normal post.

Warning: this topic has not been posted in for at least 120 days.
Unless you're sure you want to reply, please consider starting a new topic.

Name: Email:
Verification:
Type the letters shown in the picture
Listen to the letters / Request another image
Type the letters shown in the picture:
type: "Pakistan" without quotes: