What is a function specifier in C?

CServer Side ProgrammingProgramming

In C and C++ there are some function specifiers. The function specifiers are used to specify the functions property. C++ has inline function specifier. In C there is _Noreturn function specifier. This is used to denote that one function will not return anything.

Example

 Live Demo

#include<stdio.h>
int myAdd(int a, int b){
   return a + b;
}
main() {
   int x = 10, y = 20;
   printf("The value is: %d\n", myAdd(x, y));
}

Output

The value is: 30

If the _Noreturn is used it will display some warning and the program will be terminated with some error.

Example

#include<stdio.h>
_Noreturn int myAdd(int a, int b){
   return a + b;
}
main() {
   int x = 10, y = 20;
   printf("The value is: %d\n", myAdd(x, y));
}

Output

[Warning] function declared 'noreturn' has a 'return' statement
[Warning] 'noreturn' function does return
raja
Published on 26-Jul-2019 09:18:08
Advertisements