
- C Programming Tutorial
- C - Home
- C - Overview
- C - Environment Setup
- C - Program Structure
- C - Basic Syntax
- C - Data Types
- C - Variables
- C - Constants
- C - Storage Classes
- C - Operators
- C - Decision Making
- C - Loops
- C - Functions
- C - Scope Rules
- C - Arrays
- C - Pointers
- C - Strings
- C - Structures
- C - Unions
- C - Bit Fields
- C - Typedef
- C - Input & Output
- C - File I/O
- C - Preprocessors
- C - Header Files
- C - Type Casting
- C - Error Handling
- C - Recursion
- C - Variable Arguments
- C - Memory Management
- C - Command Line Arguments
- C Programming useful Resources
- C - Questions & Answers
- C - Quick Guide
- C - Useful Resources
- C - Discussion
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 Articles
- 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++?
- Difference between “int main()” and “int main(void)” in C/C++?
- Differentiate between int main and int main(void) function in C
- C/C++ difference's between "int main()" and "int main(void)"
- What is the difference between const int*, const int * const, and int const *?
- max() and min() in Python
- What does the method fill(int[], int fromIndex, int toIndex, int val) do in java?
- Difference Between int and long
- Difference between void main and int main in C/C++
- How to select max of mixed string/int column in MySQL?
- int(5) vs. int(10) in MySQL?
- Use of min() and max() in Python
- Int 64 Struct in C#
- What is the difference between size_t and int in C++?

Advertisements