People Innovation Excellence
 

Logical Operators in C

Logical Operators merupakan sebuah expression yang mengembalikan nilai true (1) atau false (0) tergantung operator yang digunakan. Berikut logical operator yang dapat digunakan di Bahasa Pemrograman C:

Operator Description Example
&& True only if all operands are true (A > 4) && (B>4), equal to 0
|| True only if either one operand is true (A > 4) || (B>4), equal to 1
! Logical NOT. True only if the operand is 0 !(A > 4), equal to 0

*Asumsi variabel A=6 dan variabel B=2

Penjelasan:

  • (A > 4) && (B > 4) equal to 0, karena operands (A > 4) = 1 dan (B > 4) = 0.
    TRUE && FALSE memberikan nilai FALSE.
  • (A > 4) || (B > 4) equal to 1, karena operands (A > 4) = 1 dan (B > 4) = 0.
    TRUE || FALSE memberikan nilai TRUE.
  • !(A > 4) equal to 0, karena operand (A > 4) = 1.
    !TRUE memberikan nilai FALSE.

Berikut truth table dari penerapan logical operators:

A B !A A && B A || B
TRUE TRUE FALSE TRUE TRUE
TRUE FALSE FALSE FALSE TRUE
FALSE TRUE TRUE FALSE TRUE
FALSE FALSE TRUE FALSE FALSE

Program komputer selalu membuat keputusan berdasarkan data atau kondisi yang dirancang pada program. Misalnya, program untuk pemantauan jantung. Program akan membunyikan alarm jika denyut nadi tiba-tiba detak jantung berhenti.

Referensi:
Paul J. Deitel. (2016). C how to program: with an introduction to C++. 08. Pearson Education. Hoboken. ISBN: 9780133976892.


Published at : Updated
Written By
Fidelson Tanzil, S.Kom., M.T.I.
Subject Content Coordinator – Basic Programming | School of Computer Science

Periksa Browser Anda

Check Your Browser

Situs ini tidak lagi mendukung penggunaan browser dengan teknologi tertinggal.

Apabila Anda melihat pesan ini, berarti Anda masih menggunakan browser Internet Explorer seri 8 / 7 / 6 / ...

Sebagai informasi, browser yang anda gunakan ini tidaklah aman dan tidak dapat menampilkan teknologi CSS terakhir yang dapat membuat sebuah situs tampil lebih baik. Bahkan Microsoft sebagai pembuatnya, telah merekomendasikan agar menggunakan browser yang lebih modern.

Untuk tampilan yang lebih baik, gunakan salah satu browser berikut. Download dan Install, seluruhnya gratis untuk digunakan.

We're Moving Forward.

This Site Is No Longer Supporting Out-of Date Browser.

If you are viewing this message, it means that you are currently using Internet Explorer 8 / 7 / 6 / below to access this site. FYI, it is unsafe and unable to render the latest CSS improvements. Even Microsoft, its creator, wants you to install more modern browser.

Best viewed with one of these browser instead. It is totally free.

  1. Google Chrome
  2. Mozilla Firefox
  3. Opera
  4. Internet Explorer 9
Close