

- Trending Categories
Data Structure
Networking
RDBMS
Operating System
Java
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
- Related Questions & Answers
- Difference between const int*, const int * const, and int const * in C/C++?
- Difference between const int*, const int * const, and int const * in C
- What is difference between int and const int& in C/C++?
- Differentiate between int main and int main(void) function in C
- What is the difference between const int*, const int * const, and int const *?
- max() and min() in Python
- Difference between “int main()” and “int main(void)” in C/C++?
- Difference Between int and long
- C/C++ difference's between "int main()" and "int main(void)"
- What does the method fill(int[], int fromIndex, int toIndex, int val) do in java?
- Use of min() and max() in Python
- Difference between void main and int main in C/C++
- int(5) vs. int(10) in MySQL?
- What is the difference between size_t and int in C++?
- What is the difference between int and Int32 in C#?
- Accessing variables of Int and Float without initializing in C
Advertisements