Example
Now, let’s see some examples of how to use the”_Noreturn” specifier.
Example 1
#include<stdio.h>
int function() {
return 100;
}
main() {
printf("The returned value: %d\n", function());
}

You can also try this code with Online C Compiler
Run Code
Output
The returned value: 100

You can also try this code with Online C Compiler
Run Code
In this example, we have created a function and returned a value of that function.
Example 2
#include <stdio.h>
#include <stdlib.h>
_Noreturn void view()
{
return 10;
}
int main(void)
{
printf("Ready to begin...\n");
view();
printf("NOT over till now\n");
return 0;
}

You can also try this code with Online C Compiler
Run Code
Output
Ready to begin…
Warning: function declared ‘nonreturn’ has a ‘return’ statement.

You can also try this code with Online C Compiler
Run Code
We have created a noretrun function to return an integer value in this example. The main function is created to call the view function since it will show compile error that noreturn has a return statement. You can practice by yourself on an online C compiler.
Frequently Asked Questions
What is the "noreturn" function in the C programming language?
It is a compiler limitation that tells the compiler that "MY code will never return."
Why does the noreturn function return an error when calling it?
When a noreturn function is used, a compiler sends a warning converted into an error message.
Why does the function noreturn() not return any value?
Noreturn does not tell the compiler that functions don't return any value. It tells the compiler that the control flow will not return to the caller.
Conclusion
In this article, we have discussed the noreturn function specifier in C. We also discussed its syntax and several examples and their outputs and explanations.
To learn more, see Operating System, Unix File System, File System Routing, and File Input/Output.
Refer to our Guided Path on Coding Ninjas Studio to upskill yourself in Data Structures and Algorithms, Competitive Programming, JavaScript, System Design, and many more! If you want to test your competency in coding, you may check out the mock test series and participate in the contests hosted on Coding Ninjas Studio! But if you have just started your learning process and are looking for questions asked by tech giants like Amazon, Microsoft, Uber, etc; you must look at the problems, interview experiences, and interview bundle for placement preparations.
Nevertheless, you may consider our paid courses to give your career an edge over others!
Do upvote our blogs if you find them helpful and engaging!
Happy Learning!