C Tutorial

C Tutorial C Language Environment Setup Execution flow of C program C printf and Scanf C Data type C Token Variable in C Operators in C Comments in C Escape Sequence in C C – Storage Classes C Decision control statement Loop Statement in C Break, continue and goto statement in C Type Casting in C Function in C Recursion in C String in C C Array Pointer in C Dynamic memory allocation C –Structure Nested Structure in C Union in C File Handling in C C pre-processor Static Function In C Sizeof In C Selection Sort In C Scope Of Variables In C Runtime Vs Compile Time In C Random Access Lseek In C Queue Implementation In C Pseudo Code In C Prototype In C Pointer To Pointer In C Pointer Arithmetic In C Passing Array To Function In C Null Character In C Merge Sort In C Macros In C Library Functions In C Memory Leak In C Int In C Goto And Labels In C Fibonacci Series In C Fflush In C Derived Data Types In C Data Types In C Const Vs Volatile In C Character Set In C Character Class Tests In C Calloc In C C Pointers Arrays In C Include In C Clrscr In C C Vs Java String Literals In C Types Of Pointers In C Variables In C Volatile In C Why C Is A Middle Level Language Infix To Postfix Program In C Ceil function in C LCM of two numbers in C Quick sort in C Static in C function pointer as argument in C Top Array Keywords in C Add two numbers using the function in C Armstrong program in C using function Array, Declaring Arrays and Array Initialization Limitations of Inline Function in C Merge and Merge sort with example in C Do-While Loop in C For Loop in C While-Loop in C Difference between while and do-while loop in C Array Of Structures in C Data Structures And Algorithms in C Types Of Structures In C How to Avoid Structure Padding in C Use of Structure in C Do WHILE LOOP in C Programming Examples For Loop in C Programming Examples Entry Control Loop in C Exit control loop in C Infinite loop in C Nested loop in C pow() function in C String Handling functions in C Prime Number code in C Factorial Program in C using For Loop Factorial Program in C Using While Loop Fibonacci Series in C Using For Loop Fibonacci series in C using while loop Prime Number Program in C using for Loop While Loop in C programming examples Built-in functions in C Assert() Function C vs Java Strings Call Back Function in Embedded C Else If Ladder fgets() function Ftell() Function getc() function getch() function gets() function Heap Sort Nested if-else statement Pi() Function Positioning of file Write() function abs() function in C Attributes in C C program to find factorial of a number using Recursion Ferror() in c fopen() function in C Fibonacci series program in C using Recursion Formatted Input and output function in C Snake Game in C User Defined Functions in C Beep() function in C Cbrt() function in C Hook() function in C Isalnum() function in C C Program to find the Roots of a Quadratic Equation C Switch Statements Difference between rand() and srand() function in C Difference between while and for loop in C Doubly Linked list in C Example of Iteration in C How to use atoi() function in C How to use floor() function in C How to use sine() function in C How to use Typedef Struct in C Integer Promotions in C C Program Swap Numbers in cyclic order Using Call by Reference C Program to Find Largest Number Using Dynamic Memory Allocation C Program to Find the Largest Number using Ternary Operator C/C++ Program to Find the Size of int, float, double and char Find the Largest Three Distinct Elements in an Array using C/C++ Loop Questions in C Modulus on Negative Numbers in C Multiplication table program in C using For loop Nested Loops in C Programming Examples C Program for Mean and Median of an Unsorted Array Results of Comparison Operations in C and C++ Reverse a Stack using Recursion in C Simple hash() function in C strcat() Function in C Sum of N numbers in C using For loop Use of free() function in C Write a program that produces different results in C and C++ C Function Argument and Return Values Keywords in C Bank management system in C Calendar application in C Floor() Function in C Free() Function in C How to delete a file in C How to move a text in C Remove an element from an array in C Unformatted input() and output() function in C What are linker and loader in C SJF Scheduling Program in C Socket Programming in C Structure in C Tower of Hanoi in C Union Program in C Variable Declaration in C What is Linked List in C While Loop Syntax in C fork() in C GCD program in C Branching Statements in C Comma Operator in C Control statement in C Double Specifier in C How to create a binary file in C Long int in C Palindrome Number in C Pure Virtual Function in C Run Time Polymorphism in C Types of Array in C Types of Function in C What is a buffer in C What is required in each C Program Associativity of Operators in C Bit Stuffing Program in C Actual and Formal Parameters Addition of two Numbers in C Advantages of function in C Arithmetic Progression Program in C Binomial Coefficient Program in C Difference between Array and List in C Diffie-Hellman Algorithm in C How to convert a number to words in C How to convert a string to hexadecimal in C Difference between If and Switch Statement in C C and C++ Binary Files C program that does not Suspend when Ctrl+Z is Pressed Different ways to Declare the Variable as Constant in C Range of Int in C C Program to find the size of a File FIFO Example in the C Language For loop in C Programming GCD program of two numbers in C GPA Calculator in C How to Calculate Time Complexity in C How to include graphics.h in C How to measure time taken by a function in C How to return a Pointer from a Function in C What is the main in C Addition of Matrix in C Booleans in C C Program for Extended Euclidean algorithms C Program of Fencing the Ground Ceil and Floor in C Compound Interest Program in C Displaying Array in C Distance Vector Routing Protocol Program in c Dos.h Header File in C Language DSA Program in C Explain the two-way selection in C Fee Management System in C File Operations in C Malloc function in C Multiplication Table in C Simple Programs in C Language tolower() Function in C Type Conversion in the C Why does sizeof(x++) not Increment x in C Advantages of Dynamic Memory Allocation in C Armstrong Number in C Assignment Operator Program in C Banker’s Algorithm in C Binary Search in C with Best and Worst Time Complexity Caesar Cipher Program in C Call by Value and Call by Reference in C Conditional Operator in C CRC Program in C Deadlock Detection Program in C Decimal to Binary in C Difference between If Else and Nested If Else in C Difference between Pre-increment and Post-increment in C Difference between Scope and Lifetime in C Evaluation of Arithmetic Expression in C Explain the Increment and Decrement Operators in C Fseek Function in C Functions in C How to Find Square Free Numbers in C Length of an Array Function in C OpenGL in C Projects on C language in 2023 Purpose of a Function Prototype in C Stdio.h in C Two-Dimensional array in C What is String Comparison in C C Compilers for Windows Functions and Recursion in C How to Declare Boolean in C How to Declare Character in C How to Round up a number in C How to use strlen() in C Pointer Declaration in C Algorithm for String Palindrome in C C Program to find ASCII value of a character Constant Pointer in C How to find string length in C using strlen() function Implicit and Explicit in C Indirect Recursion in C Input and Output functions in C isupper() in C Jump Statement in C Lifetime of a Variable in C Linker Error in C Language Numeric Constant in C Size of Pointer in C Square Root in C Language Static and Dynamic Memory allocation String Declaration in C Strong Number in C Symmetric Matrix in C Types of C Tokens What is a Size of Pointer in C What is Increment and Decrement Operator in C 1 2 3 4 Series Program in C Advantages and Disadvantages of C Language C Program for Polynomial Addition C Program to Count the Number of Vowels in a String C Programming Errors and Solutions Compilation Errors in C Complex C Programs Difference between Argument and Parameter in C Difference between char s[] and char *s in C Evaluation of Postfix Expression Using Stack in C Find Leftmost and Rightmost Set Bit of a Number fprintf and fscanf in C Introduction to Dynamic Array in C Print Address in C Realloc function in C Ternary Operators in C Types of Tokens in C with Examples Difference between Static and Dynamic Memory Allocation in C Addition Program in C Array Definition in C Array of Pointers in C Arrow Operator in C Average of Two Numbers in C Binary to Decimal in C Binary to Octal in C BREAK STATEMENT in C C Programming Operators Questions C Programs Asked in Interview Calculator Program in C C Program to Read and Print an Employee's Detail Using Structure Bubble Sort Algorithm in C C Program to Find Area and Perimeter of Circle C Program to Check Whether a Given Number is Even or Odd C in Roman Numerals C Program to Make a Simple Calculator Using Switch Case Insertion Sort Program in C How to take input in string in C GCC Conflicting Types in C Function Definition in C Format Specifier for Hexadecimal in C Flowchart in C Float in C Fizzbuzz Implementation in C Conditional Statement in C Conio.h functions list in C Constants in C Dynamic Array in C Decision Making Statements in C Continue Statement in C Creation of Thread in C DFS Algorithm in C Difference between parameter and arguments in C Dijkstra's Algorithm in C Leap Year Program in C Jump Statements in C Modulus Operator in C Memory Allocation in C Simple Interest Program in C Reverse Array in C Recursive Function in C Queue in C Printing Pascal’s Triangle in C Preprocessor Directives in C Perror() in C Perfect Number in C Programming Language Parameter Passing Techniques in C Pascal Triangle in C Patterm Program in C Affine cipher in C Dereferencing pointer in C Internal static variable vs External static variables in C Difference between exit(0) and exit(1) in C Booth's Algorithm in C Condition Control Statements in C Double Specifier in C Dynamic variables in C How to print alphabets in C How to print char array in c Order of Evaluation in C Order of Operations in C Semantic Error in C Size of String Variable in C SJF PREEMPTIVE SCHEDULING PROGRAM C: Tree in C Arithmetic Progression Program in C Array, Declaring Arrays, and Array Initialization ARRAYS IN C Assert() Function in c Atoi in C Bar3d() function in C Graphics Beep function in c Bigint (BIG INTEGERS) in C with Example Builtin functions of GCC compiler Fibonacci series in C Priority Queue in C 2D ARRAY IN C 7 Best IDEs for C/C++ Developers in 2022 Addition of Two Numbers in C Advantages and Disadvantages of C Language Advantages of Function in C Algorithm for String Palindrome in C What is fgets in C language 2d Shearing Program in C Recursion Questions In C Static Identifier in C Inserting elements in an array using C Language complex.h Header File in C fsetpos()(set file position) in C Comparator function of qsort() in C Print Hex in C strnset() function in C %d in C Butterfly Star pattern in C C form format in Excel Scan Line Polygon Filling in C 8 Queens Problem in C Back Trace in C BSS (Block Started by Symbol) Data Segment in C language Class C in Networking Strings in C Programming What is Circular linked list? What is Loop in C BITWISE OPERATOR IN C LANGUAGE BOMB DIFFUSION PROGRAM IN C LANGUAGE

Preprocessor Directives in C

We must remember a preprocessor is a compilation technique that runs while the developer runs this system. It is a pre-manner of the execution of software using c/c language.

To initialize a way of preprocessor instructions, it is mandated to define with a hash symbol (#). In any other case, it can be the non-clean individual, and for higher readability, a preprocessor directive should start inside the first column.

A header document contains C declarations and macro definitions (see Macros) to be shared among multiple source files. You request the usage of a header file to your program by way of consisting of it, with the C preprocessing directive ' # included. '

List of Preprocessor Directives:

To execute a preprocessor software on a selected announcement, a number of the preprocessor directives types are:

  • #define: It substitutes a preprocessor for using the macro.
  • #include: It allows inserting a sure header from another record.
  • #undef: It undefines a positive preprocessor macro.
  • #ifdef: It returns actually if a particular macro is defined.
  • #ifndef: It returns correctly if a particular macro isn't defined.
  • #if, #elif, #else, and #endif: It assesses this system using nice condition; these directives can be nested too.
  • #line: It handles the line numbers at the mistakes and warnings. It can alternate the line range and source files while generating output throughout compile time.
  • #errors and #caution: It may generate errors and warnings.
  • #errors can be accomplished to stop compilation.
  • #warning is finished to keep compilation with messages inside the console window.
  • #area and #endregion: To define the sections of the code to make them more understandable and readable, we will use the location of the using boom and crumble functions.

Process Flow of Preprocessor Directives:

  1. A developer writes a C program-> and this system checks if any preprocessor directives are available.
  2. If to be had, it will perform the movement event of the preprocessor, and the compiler will generate the item code.
  3. It will visit the compiler if no preprocessor directives are to be had.
  4.  The compiler will then generate the object code found through the manner of execution of the code through a linker.

Within this tutorial, we can study the numerous examples of preprocessor directives.

Four Major Preprocessor Directives:

1. MACRO EXPANSION:

In Macro expansion, we can specify two types of Macros with arguments: We also can skip arguments to macros, and it may be defined with arguments that carry out in addition to functions.

Syntax:

#define name substitute text

Where,

  1. Name: Here, we will define the micro template.
  2. Replacement textual content: we can outline it because of the macro growth.
  3. To write a macro call, we want to use capital letters.
  4. For better clarity, we can outline proper names on sure macros.
  5. To alter the program: We can alternate handiest the macro, which can replicate at the software. Hence we do now not need to alternate it whenever.
  6. The C preprocessor is a macro preprocessor (lets you define macros) that transforms your utility earlier in advance than it is compiled.
  7.  These modifications can encompass header documents, macro expansions, and so on.
  8. All preprocessing directives start with a # symbol.

Some of the commonplace uses of C preprocessors are:

Including Header Files: #include

The #include of the preprocessor is used to encompass header files to C programs. For instance,

#include <stdio.h>

Here, stdio. h is a header record. The #include preprocessor directive replaces the above line with the contents of the stdio—h header file.

That's the reason why you want to apply #include <stdio.h> earlier than you may use features like scanf() and printf().

You can also create your personal header report containing characteristic announcements and include the usage of this preprocessor directive on your program.

#include “my_header.h”

Macros using #define

A macro is a fragment of code this is given a name. You can define a macro in C using the #define preprocessor directive.

Here's an instance.

#define c 299792458 // speed of light

When we use c in our application, it is replaced with 299792458.

Example-1:

#include <stdio.h>
#define PI 3.1415
int main()
{
 float radius, area;
 printf("Enter the radius: ");
 scanf("%f", &radius);
 // Notice the use of PI
 area = PI*radius*radius;
 printf("Area=%.2f",area);
 return 0;
}

OUTPUT:

PREPROCESSOR DIRECTIVES IN C

Function like Macros:

You also can outline macros that paint similarly as a characteristic call. This is referred to as function-like macros. For instance,

#define circle area(r) (3.145*(r)*(r))

Every time this system encounters circleArea(argument), it is changed with the aid of (3.1415*(argument)*(argument)).

Suppose we exceeded five as an argument then, it expands as below:

circle Area(5) expands to (3.1415*5*5)

Example-2: Using #define preprocessor

#include <stdio.h>
#define PI 3.1415
#define circle area(r) (PI*r*r)
int main() {
 float radius, area;
 printf("Enter the radius: ");
 scanf("%f", &radius);
 area = circleArea(radius);
 printf("Area = %.2f", area);
 return 0;
}

OUTPUT:

PREPROCESSOR DIRECTIVES IN C

2. FILE INCLUSION:

  • Using this preprocessor, we can encompass a document in every other record.
  • Generally, through this preprocessor, we include the Header document.
  • A header document is a source report that contains ahead assertion of predefined features, global variables, constants value, predefined datatypes, predefined systems, predefined macros, and inline capabilities.
  • H files don’t offer any implementation part of predefined features; it gives the most effective ahead statement (prototype).
  • A c software is a combination of predefined and person-described functions.
  • C report contains the implementation part of person-defined functions and calling statements of predefined capabilities.
  •  Excellent judgment should be required if the functions are person-defined or predefined.
  • Project-related. Obj files provide the implementation of person-defined functions; Lib documents present the implementation part of pre-described capabilities that are loaded at the time of linking.
  • According to the characteristic approach, while we call a characteristic described later for fending off the compilation errors, we must head for forwarding assertion, i.E. Prototype is needed.
  •  If the feature is consumer-described, we will offer ahead announcement explicitly, but if it's miles the predefined feature, we must apply a header record.
  •  In the C programming language, .h files provide prototypes of pre-described characteristics.
  •  As a programmer, it's miles feasible to offer the ahead announcement of predefined function explicitly, but while we are offering forward assertion, then the compiler thinks it's far a person-defined function, so not advocated; .h files don't skip for the compilation process; however .h report code is compiled.
  •  When we include any header documents during preprocessing, that header document code might be substituted into the current supply code. With the current source code, the header report code also assembles.

Syntax:

#include TypeYourfilename
  1. We can update the content material within the filename when a particular directive is written.
  2. We can use a report-inclusive directive and encompass the header documents inside the applications.
  3. We can integrate function assertion, macros, and declarations of the outside variables in the top header report in preference to repeating each good judgment inside the program.

4. The stdio. H header file consists of the feature declarations and might provide statistics about the entry.

Example of the file inclusion statement:

1) #include “DefineYourfile-name": In this situation, we can seek a document within the current running directory thru easy seek.

2) #include: In this case, we can define a certain listing and search for a report.

#include<filename.h>:

Using this syntax, while we're such as header file, it will likely be loaded from the default listing, i.E. C: TCINCLUDE. Generally, via this syntax, we are which include pre-described header files. When we're along with predefined header documents. When we're along with user-defined header documents using this syntax, we need to vicinity a user-described header document in a predefined header listing, i.E. C: TCINCLUDE.

#include “filename.h”:

Using this syntax, while we include a header, it's miles loaded from the current running directory. Generally, by using this syntax, we include consumer-described header documents. By the usage of this syntax, when we include predefined header files, then first, it's going to seek within the current assignment listing. If it isn't always to be had, then loaded from the default listing, so it's far a time-taking manner.

We encompass my header.h in both my header.c and predominant. c. The usage of the # consists of the directive. This lets us access the function assertion for myFunction() in the primary. c.

Note that the header record guards (#ifndef and #outline) are in my header.h are used to prevent more than one inclusion of the header record. The #endif directive marks the quit of the header file.

3. CONDITIONAL COMPILATION:

  • We can use conditional compilation on a positive common sense in which we want to outline a situation logically.
  • It uses directives like #if, #elif, #else, and #endif.

In this technique, the preprocessor depends on whether the conditional block call is to be handed from the compilation procedure or now not, which is decided at the time of preprocessing. If the circumstance is authentic, the block can be bypassed from the compilation process; if the circumstance is fake, then the complete block of the statements will be eliminated from the source at the time of the preprocessor.

The total gain of this preprocessor is decreasing. Exe document size because while source code is decreased, then automatically item code is reduced, so exe document length can also be reduced. Let us see an example for information this concept:

Program-1:

#include <stdio.h>
#define PI 3.1415
#define circle area(r) (PI*r*r)
int main() {
 float radius, area;
 printf("Enter the radius: ");
 scanf("%f", &radius);
 area = circleArea(radius);
 printf("Area = %.2f", area);
 return 0;
}

OUTPUT:

PREPROCESSOR DIRECTIVES IN C

In the above program, the time of preprocessing circumstance comes to be false, so automatically correspondent block can be removed from the source, and it passes to compilation. So, by using a conditional compilation preprocessor, we can reduce the dimensions. Exe report because when preprocessing with the aid of disposing of the statements, it automatically reduces the obj report size. Exe record size decreased.

Program-2:

#include <stdio.h>
void main ()
{
 printf ("CTUTORIAL");
 #if 2>5!=2<5
 printf ("A");
 printf ("B");
 #else
 printf ("C");
 printf ("D");
 #endif
 printf ("Welcome");
}

OUTPUT:

PREPROCESSOR DIRECTIVES IN C

Program-3:

#include <stdio.h>
void main ()
{
 printf ("CTUTORIAL");
 #if 2>5!=0
 printf ("A");
 printf ("B");
 #elif 5<0
 printf ("C");
 printf ("D");
 #else
 printf ("Hi");
 printf ("Bye");
 #endif
}

OUTPUT:

PREPROCESSOR DIRECTIVES IN C

#ifdef & #ifndef:

The Macro Testing Conditional Compilation Preprocessor is also known as #ifdef and #ifndef. When using this preprocessor, code will compile efficaciously (relying on the macro kingdom) if the most effective requirement is met. We may save several code substitutions in the header file using this preprocessor.

Program using #ifdef:

#include <stdio.h>
#define TUTORIAL
void
main ()
{
 printf ("WELCOME");
 #ifdef TUTORIAL
 printf ("Hi");
 printf ("Bye");
 #endif
}

OUTPUT:

PREPROCESSOR DIRECTIVES IN C

Program using #ifndef:

#include <stdio.h>
#define TUTORIAL
void main ()
{
 printf ("WELCOME");
 #ifndef TUTORIAL
 printf ("Hi");
 printf ("Bye");
 #endif
}

OUTPUT:

PREPROCESSOR DIRECTIVES IN C

In the previous program, if the TUTORIAL macro is not described, then the corresponding code block isn't passing for the compilation manner. TUTORIAL is known as null macro as it has no substitute textual content.

Program-4:

#include <stdio.h>
#define Test
void main ()
{
 printf ("WELCOME");
 #ifndef Test
 printf ("A");
 printf ("B");
 #endif
 printf ("Hello");
}

OUTPUT:

PREPROCESSOR DIRECTIVES IN C

#undef:

Using this preprocessor, we can close the scope of an existing macro. Generally, this macro is needed while we're redefining a current macro. After final the scope of a macro, it is only possible to get the right of entry to it once it is redefined.

#include<stdio.h>
#define A 11
void main ()
{
 printf ("%d," A);
 // A =22 Error because here A is constant; it is already replaced with 11
 // #define A 22 Error because A is already defined with 11; we cannot do this
 #undef A // first under, then def
 #define A 22
 printf ("%d," A);
 #undef A
 #define A 33
 printf ("%d," A);
 #undef A
 // printf("%d", A); Error
}

OUTPUT:

PREPROCESSOR DIRECTIVES IN C
  • The conditional compilation offers a manner that includes or omits selected traces of supply code relying on the values of literals specified using the DEFINE directive.
  •  In this manner, you can create multiple versions of the same software without holding separate supply streams.
  • Conditional compilation is the process of selecting which code to compile and which code to now not collect, similar to the #if / #else / #endif in C and C.
  • Any announcement that isn't compiled in still should be syntactically accurate.
  • Conditional compilation involves condition checks which can be evaluable at assemble time.
  • Each directive controls the block right now, following it.
  • A block includes all the tokens beginning on the road following the directive and ending at the subsequent conditional compilation directive at the identical nesting degree.
  • Each directive will be processed within the order in which it is encountered. If an expression evaluates to zero, the block following the directive is ignored.

4. MISCELLANEOUS DIRECTIVES:

We can observe two directives apart from those that are not commonly used.

  • #undef: We can also use this directive with the #define directive. It is used to undefine a designated macro.
  • #pragma: We can also use this directive on a sure stage in which we want to define turn-on or off-unique features. We can use those directives for the compiler-particular, which has a particular range compared to the compiler.

Examples of #pragma directives are noted below: #pragma startup and #pragma go out: These directives push to suggest the features that are required to run before this device as a startup (earlier than the manipulate movements to maximum vital()) and in advance than this device go out (only before the manipulate returns from important()).

#pragma Miscellaneous Directives in C:

It is a compiler-established preprocessor, i., E. All compilers don't help this preprocessor. A processor directive that isn't certain through ISO is famous. Pragmas offer to manage the movements of the compiler and linker. #pragma is a numerous directive. This is used to turn on or off specific skills. It varies from compiler to compiler. If the compiler is not recognized, then it ignores it.#pragma begin-up and #pragma go out are used to specify which function has to be called upon begin-up (earlier than primary ()) or application exit (just before this system terminates). Startup and go-out functions should now not acquire or return any values. #pragma was used to suppress (ignore) particular warning messages from the compiler.

  1. #pragma warn –rrl: Return price warnings
  2. #pragna warn –par: Parameter no longer used warnings
  3. #pragma warn –rch: Unreachable code warnings

Program:

#include<stdio.h>
void ABC ();
void xyz ();
#pragma startup abc
#pragma exit xyz
void func1 ()
{
 printf ("Hello ABC");
}
void func2 ()
{
 printf ("Hello xyz");
}
int main ()
{
 printf ("Hello main()");
 return 0;
}

OUTPUT:

PREPROCESSOR DIRECTIVES IN C

This takes place due to the fact GCC does now not help the #pragma startup or exit. However, you may use the code underneath for the same GCC compiler output.

Program to understand Miscellaneous Directives in C Language:

#include<stdio.h>
void ABC ();
void xyz ();
void __attribute__ ((constructor)) abc ();
void __attribute__ ((destructor)) XYZ ();
void abc()
{
 printf ("Hello abc \n");
}
void xyz()
{
 printf("Hello xyz\n");
}
int main()
{
 printf ("Hello main()\n");
 return 0;
}

OUTPUT:

PREPROCESSOR DIRECTIVES IN C
  • In the preceding program, the “ABC" feature is loaded first before loading the main characteristic, and the "XYZ" function is loaded after loading the primary feature.
  • Between startup and exit, automatically, the main feature is executed.
  • In an implementation, while we have extra than one startup and go-out function, then, according to the concern, we will execute those capabilities.
  • In #pragma startup, the characteristic with the very best precedence will be executed first, and which has the least precedence may ultimately be accomplished before the primary().
  • In #pragma startup, the ultimate precise characteristic might be accomplished first while identical priority occurs.
  • In #pragma exit, the feature with the best priority can be executed in cease, and the least priority will be done first after the predominant() most effective.
  • In #pragma exit, the closing detailed characteristic will be finished first while equal priority occurs.

# Miscellaneous error Directives in C

Using this preprocessor, we can create user-defined mistake messages during compilation.

Program to understand #error Miscellaneous Directives in C:

#include<stdio.h>
#define NIT
void main ()
{
 #ifndef NIT
 #error NIT MACRO NEEd TO BE DEFINE
 #endif
 #ifdef NIT
 printf ("Welcome\t");
 printf ("NIT");
 #endif
}

OUTPUT:

PREPROCESSOR DIRECTIVES IN C

In the preceding software, ifNIT MACRO isn't defined, it offers the mistake when compiling.

#line Miscellaneous Directives in C

We can create customer-defined line sequences in an intermediate report using this preprocessor. It is used to reset the road amount in the code.

Program to understand #line Miscellaneous Directives in C:
#include<stdio.h>
void main ()
{
 printf ("A\n");
 #if 5>2!=1
 printf ("NIT");
 printf ("B");
 #endif
 #line 4
 printf ("Welcome\t");
 printf ("C");
}

OUTPUT:

PREPROCESSOR DIRECTIVES IN C

When the preceding code is preprocessed, the road series is reset to 4.

CONCLUSION:

This article helps us to understand the Preprocessor Directives. In this text, we discussed the diverse definitions and strategies of the Preprocessor Directives with the pattern code using c# or C /C programming.

We additionally discovered their kinds with respective syntax and instance. This article may be beneficial to expert builders in application improvement. Internet and JAVA backgrounds, software architectures, cloud professionals, testers, and newbies seek out different uses of numerous forms of mechanisms of Spring Data.

Besides pursuing numerous guides furnished by using Simplilearn, you could join our SkillUp platform, a Simplilearn initiative, which gives more than one free online course to assist novices in recognizing the basics of several programming languages, along with Preprocessor Directives in C.

You can also pick out our Full-stack Web Development Certification Course to beautify your professional possibilities by analyzing every backend and frontend with precise equipment like SpringBoot, AngularMVC, JSPs, and Hibernate.