Showing posts with label Introduction to c. Show all posts
Showing posts with label Introduction to c. Show all posts

Tuesday, March 5, 2024

INTRODUCTION TO THE PRE PROCESSOR IN C

Introduction to the pre-processor in C

  • Introduction to pre-processor 
  • Pre-preprocessor 
  • Macro substitution 
  • File inclusion directives 
  • Conditional compilation 

The compilation does not begin with the C Preprocessor; rather, it is an independent procedure. A simple text replacement tool that tells the compiler to do any necessary preparation before compilation is a C preprocessor.


A macro processor called the C preprocessor is automatically used by the C compiler to make certain alterations before compiling your program. Because it can define macros—shorthand for more complicated constructions—the program is termed a macro processor
.

There are four independent features available to you in the C preprocessor:

  •       The header files are a part of this. You can replace these declaration files in your software.
  •       The C preprocessor can replace actual macros in the program with designed macros with the use of macro extensions. Any element of C code can have its definition shortened by a macro.
  •        Conditional collection and precise preprocessing instructions enable the program components to be included or excluded based on different scenarios.
  •       Line management when you use a program to merge or reorganize source files into an intermediate file that is then compiled, you can use line control to tell the compiler where the source line originally came from.

 

Preprocessor directives

Beginning with the hash symbol (#), all preprocessor commands go here. For readability, preprocessor directives must begin with the first nonblank character in the first column. This is a complete guide to the most important preprocessor commands –



Macro substitution

The name and text that should be changed in a macro are specified by the #define directive. The preprocessor simply replaces the macro's name with the replacement text in the line of code where the macro is created.

Now we will try the C program


File inclusion directives
  1. The document contains Directories used to include user-defined header files in C programs.
  2. The file-inclusive directory looks for the header file inside the same directory if the path is left blank.
  3. The first step in file-inclusive directives is #include.
  4. By giving its path, you can add a certain header file to the current scope.
  5. Instead of using triangular brackets to include user-defined header files, we employ "Double Quote".
  6. It instructs the compiler to incorporate each named file.

Conditional compilation

Conditional Compilation: We can choose not to compile code that does not match specific requirements or to only compile code that does by using conditional compilation directives.

  1. #ifdef: This is the simplest type of conditional directive. This type of block is known as a conditional group. The controlled text will appear in the preprocessor output if the macro name is defined. The controlled text will include preprocessing directives inside a conditional. Their implementation is reliant on the conditional's success. You can stack them in layers, but they have to be fully nested. Put simply, '#endif' always matches the nearest '#ifdef' (or '#ifndef') or '#if'. Furthermore, you cannot create and terminate a conditional group in different files.ss

Syntax:

#ifdef MACRO

    controlled text

#endif /* macroname */

INTRODUCTION TO C

Introduction to C

• An Overview of A C

• Similarities and distinctions between C and C++

• The benefits and drawbacks of utilizing C

• Commencing with the C

Dennis Ritchie of the Bell Labs created the general-purpose structural and procedural computer programming language C around 1972.

It is called the fundamental of the Programming language or a base of all kinds of programming languages.

It is closely related to UNIX because it was developed for the UNIX operating system along with other databases and applications.

Because it is one of the starting programming languages therefore if we learn it then we never have an understanding of other programming languages such as C++, JAVA, C#, and Python.

C, despite its advanced age, remains remarkably quick and versatile, finding potential applications in the development of device drivers, protocol stacks, and games. There are multiple versions available, including C89/C90, C99, C11, and C18. The ANSI C and ISO C standards were released in 1989 and 1990, respectively.

Examining C and C++

C++ is a more advanced version of C that was created by Bjarne Stroustrup after the development of C.

C++ and C are two programming languages that have unique features and qualities. C++ and C are two different programming languages with distinct characteristics. C++ is an object-oriented language that provides features such as classes and objects, while C is a procedural language.


C follows a different methodology compared to C++. While C takes a top-down approach, C++ utilizes a bottom-up strategy. C contains 32 keywords but C++ can contain 63 keywords.

C supports built-in data types but C++ contains both Built-in as well as user-defined data types.

C didn’t have an access modifier but C++ has.

C does not support reference variables but C++ does.

C has code in separate blocks known as functions but C++ code is divided into objects and class.

C is being used in MySQL, Windows Kernel, Oracle Database, Telegram Messenger, etc. and C++ is used in Google Chrome, Microsoft Office, 3-D games, etc.

 

Similarities between C and C++


C and C++ share a great deal of code in common.

They both have similar compilers and are constructed with the same syntax.

The file scope, heap, and stack variables have the same names in both.

Most of C++'s operators and keywords are also found in C.

 Advantages of C

1.       Effectiveness: C's speed and efficiency allow for the development of high-performance applications.

2.       Because C programs are OS- and cross-platform-neutral, they are incredibly portable.

3 C is considered optimal for systems programming and operating system development due to its ability to grant low-level access to system resources.
4. An abundance of information and resources are accessible to developers as a result of C's sizable and active user community.
5. C is extensively utilized, as demonstrated by the fact that numerous contemporary programming languages utilize it as their foundational language. 

Disadvantages:

 

1.  Because of its complex syntax and low-level access to system resources, C has a steep learning curve that complicates the learning process, particularly for newcomers.

2 Inadequate handling in C, which lacks automated memory management, can result in memory leakage and other complications associated with memory.
3 Object-oriented programming in C is more difficult to implement than in languages like Python or Java, primarily because of C's inadequate support for such programming paradigms.
4. In contrast to programming languages like Java or Go, C is less suitable for the development of multithreaded applications on account of its lack of inherent concurrency support.
5 When C applications are written without proper attention, they may have security risks, such as buffer overflows.

In summary, while C is an influential programming language that offers numerous benefits, it is not devoid of limitations, particularly for novice programmers or individuals engaged in intricate endeavors.
Beginning with the letter C

It is not possible to set English as the default language, as communicating with a computer necessitates the use of a language that it can comprehend.
Nevertheless, there is a notable resemblance in the manner in which English is learned: it commences with memorization of the alphabet, then progresses to the comprehension of letter combinations that constitute words, which subsequently constitute sentences, which constitute paragraphs, and so forth.
Constraints, variables, and keywords—essential building blocks of the C programming language—must also be comprehended before constructing an instruction in the language.


A group of instruction would be combined later on to form a program which is displayed above.

Featured Post

ASSOCIATION RULE IN MACHINE LEARNING/PYTHON/ARTIFICIAL INTELLIGENCE

Association rule   Rule Evaluation Metrics Applications of Association Rule Learning Advantages of Association Rule Mining Disadvantages of ...

Popular