You are here

C++ inline function program

Inline function: You can make a function inline by writing the keyword inline before defining the function.

C++ programming code

#include <iostream>
 
using namespace std;
 
int check_digit(char);
 
int main() {
  char c;
 
  cout << "Enter a character\n";
  cin >> c;                                 
 
  if ( check_digit(c) ) {
    cout << c << " is a digit.\n";
  }
  else {
    cout << c << " is not a digit.\n";
  }
 
  return 0;
}
 
inline int check_digit(char c) {
  if ( c >= '0' && c <= '9' ) {
    return 1;
  } 
  else {
    return 0;
  }
}

C++ programming code for inline function using class

#include <iostream>
 
using namespace std;
 
class programming {
  char c;
 
  public:
    void input();
    void output();
};
 
inline void programming::input() {
  cin >> c;
}
 
void programming::output() {
  cout << c << endl;
}
 
int main() {
  programming object;
 
  object.input();
  object.output();
 
  return 0;
}