Pages

Wednesday, January 1, 2025

C- Operator and their uses with examples

C- Operator and their uses with examples



1. Unary Operator
a) num-- means decrement of 5 to 4 as an example! :)

// Online C compiler to run C program online
#include <stdio.h>

int main() {
   int num = 5;
   
   printf("The value of 5 before decrement is:- %d", num);
   printf("\nThe value of 5 using decrement is:- %d", num--);
   printf("\nThe value of 5 after decrement is:- %d", num);
   
    return 0;
}

OUTPUT:-
The value of 5 before decrement is:- 5
The value of 5 using decrement is:- 5
The value of 5 after decrement is:- 4

=== Code Execution Successful ===

b) num++ is the vice-e-versa of num--
// Online C compiler to run C program online
#include <stdio.h>

int main() {
   int num = 5;
   
   printf("The value of 5 before decrement is:- %d", num);
   printf("\nThe value of 5 using decrement is:- %d", num++);
   printf("\nThe value of 5 after decrement is:- %d", num);
   
    return 0;
}


OUTPUT :-
The value of 5 before decrement is:- 5
The value of 5 using decrement is:- 5
The value of 5 after decrement is:- 6

=== Code Execution Successful ===

No comments:

Post a Comment

3917. Count Indices With Opposite Parity (Brute Force) O(n2) + Optimized Solution O(n) + tips LEETCODE WEEKLY 500

  class Solution {     public int [] countOppositeParity ( int [] nums ) {          // approach 1 - checks every pair         int n = n...