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

Stack using Linked List – Partial (University Exam Topic)

 #include <iostream> using namespace std; struct Node {     int data;     Node* next; }; class Stack {     Node* top; public:     Stac...