_Noreturn function specifier in C


The _Noreturn function specifier is used to tell to the compiler that the function will not return anything. If the program uses some return statement inside it, the compiler will generate compile time error.

Example Code

#include<stdio.h>
main() {
   printf("The returned value: %d
", function); } char function() {    return 'T'; //return T as character }

Output

The program terminates abnormally
[Warning] function declared 'noreturn' has a 'return' statement

Now if it is a normal function it will work fine.

Example Code

#include<stdio.h>
int function() {
   return 86; //try to return a value
}
main() {
   printf("The returned value: %d
", function()); }

Output

The returned value: 86

Updated on: 30-Jul-2019

134 Views

Kickstart Your Career

Get certified by completing the course

Get Started
Advertisements