Data Structure
Networking
RDBMS
Operating System
Java
MS Excel
iOS
HTML
CSS
Android
Python
C Programming
C++
C#
MongoDB
MySQL
Javascript
PHP
- Selected Reading
- UPSC IAS Exams Notes
- Developer's Best Practices
- Questions and Answers
- Effective Resume Writing
- HR Interview Questions
- Computer Glossary
- Who is Who
INT_MAX and INT_MIN in C/C++ and Applications
In this tutorial, we will be discussing a program to understand INT_MAX and INT_MIN in C/C++.
INT_MIN and INT_MAX are macros that are defined to set the minimum and maximum value for a variable/element.
Example
#include<bits/stdc++.h>
int main(){
printf("%d\n", INT_MAX);
printf("%d", INT_MIN);
return 0;
}
Output
2147483647 -2147483648
Application
Calculating MIN value in an array
Example
#include <bits/stdc++.h>
//calculating minimum element in an array
int compute_min(int arr[], int n){
int MIN = INT_MAX;
for (int i = 0; i < n; i++)
MIN = std::min(MIN, arr[i]);
std::cout << MIN;
}
int main(){
int arr[] = { 2019403813, 2147389580, 2145837140, 2108938594, 2112076334 };
int n = sizeof(arr) / sizeof(arr[0]);
compute_min(arr, n);
return 0;
}
Output
2019403813
Advertisements