Warning: sizeof(): Parameter must be an array or an object that implements Countable in /homepages/9/d213665487/htdocs/clickandbuilds/CoalGeology/wp-content/plugins/wordpress-firewall.php on line 245

Warning: sizeof(): Parameter must be an array or an object that implements Countable in /homepages/9/d213665487/htdocs/clickandbuilds/CoalGeology/wp-content/plugins/wordpress-firewall.php on line 245

Warning: Cannot modify header information - headers already sent by (output started at /homepages/9/d213665487/htdocs/clickandbuilds/CoalGeology/wp-content/plugins/wordpress-firewall.php:245) in /homepages/9/d213665487/htdocs/clickandbuilds/CoalGeology/wp-content/plugins/wp-super-cache/wp-cache-phase2.php on line 62
Unary Vs. Binary Operators in C with Example code – Coal Geology and Mining: Consulting Services

Unary Vs. Binary Operators in C with Example code

//Unary Vs. Binary Operators
// multiplication is a binary operator
//unary operators only needs one operand.

//Let’s make a C program to check this matter in more detail.

#include <stdio.h>
int main(void) {
int bank;
int expenditure;
int final;

bank=1000; //declare variable. we are ignoring pennies here!
expenditure=100;
final=bank-expenditure; // – is a binary operator here.

printf(“Final bank acccount is %d\n\n”, bank);
printf(“Expense is %d\n\n”, -expenditure); // – is acting like an unary operator
return 0;
}

 

Output:

Capture

Leave a Comment

Your email address will not be published. Required fields are marked *