The document summarizes key aspects of the C preprocessor including macro substitution, file inclusion, compiler control directives, and ANSI additions. It discusses how the preprocessor processes source code before compilation through text substitution and conditional compilation. Common preprocessor directives like #define, #include, #if, #else, and #error are described along with uses for macro definitions, file inclusion, and conditional compilation. New ANSI additions like #elif, #pragma, and stringizing operators are also covered.
A pointer is a variable whose value is the address of another variable, i.e., direct address of the memory location. Like any variable or constant, you must declare a pointer before you can use it to store any variable address.
There are few important operations, which we will do with the help of pointers very frequently. (a) we define a pointer variable (b) assign the address of a variable to a pointer and (c) finally access the value at the address available in the pointer variable. This is done by using unary operator * that returns the value of the variable located at the address specified by its operand.
The ppt describes usage of functions in c language. Showing basic use of function and determining the differences between function call by value and function call by reference using pointer. It also includes valid use in swapping two numbers in c along with different outputs. Overall its a basic note for c language.
A pointer is a variable whose value is the address of another variable, i.e., direct address of the memory location. Like any variable or constant, you must declare a pointer before you can use it to store any variable address.
There are few important operations, which we will do with the help of pointers very frequently. (a) we define a pointer variable (b) assign the address of a variable to a pointer and (c) finally access the value at the address available in the pointer variable. This is done by using unary operator * that returns the value of the variable located at the address specified by its operand.
The ppt describes usage of functions in c language. Showing basic use of function and determining the differences between function call by value and function call by reference using pointer. It also includes valid use in swapping two numbers in c along with different outputs. Overall its a basic note for c language.
C Preprocessor directives:
i\ Before a C program is compiled in a compiler, source code is processed by a program called preprocessor. This process is called preprocessing.
Commands used in preprocessor are called preprocessor directives and they begin with “#” symbol.
The preprocessor, as its name implies, is a program that processes the source code before it passes through the compiler. It operates under the control of what is known as preprocessor command lines or directives.
Preprocessor directives are placed in the source program before calling the function main( ).
Before the source code passes through the compiler, it is examined by the preprocessor for any preprocessor directives. If there are any, appropriate actions (as per the directives) are taken and then the source program is handed over to the compiler.
These slides contain the concept of Macros. Macros in C Language are very powerful and used mostly to reduce the time and size of a code. It also allows reusing the code
JIMS BCA Curriculum includes Macros in Unit V of Programming Using C Subject.
JIMS provides an updated Curriculum and includes the concepts in depth.
Admission to BCA is Open.
https://www.jimssouthdelhi.com/admission-procedure.html
The French Revolution, which began in 1789, was a period of radical social and political upheaval in France. It marked the decline of absolute monarchies, the rise of secular and democratic republics, and the eventual rise of Napoleon Bonaparte. This revolutionary period is crucial in understanding the transition from feudalism to modernity in Europe.
For more information, visit-www.vavaclasses.com
Palestine last event orientationfvgnh .pptxRaedMohamed3
An EFL lesson about the current events in Palestine. It is intended to be for intermediate students who wish to increase their listening skills through a short lesson in power point.
Unit 8 - Information and Communication Technology (Paper I).pdfThiyagu K
This slides describes the basic concepts of ICT, basics of Email, Emerging Technology and Digital Initiatives in Education. This presentations aligns with the UGC Paper I syllabus.
Embracing GenAI - A Strategic ImperativePeter Windle
Artificial Intelligence (AI) technologies such as Generative AI, Image Generators and Large Language Models have had a dramatic impact on teaching, learning and assessment over the past 18 months. The most immediate threat AI posed was to Academic Integrity with Higher Education Institutes (HEIs) focusing their efforts on combating the use of GenAI in assessment. Guidelines were developed for staff and students, policies put in place too. Innovative educators have forged paths in the use of Generative AI for teaching, learning and assessments leading to pockets of transformation springing up across HEIs, often with little or no top-down guidance, support or direction.
This Gasta posits a strategic approach to integrating AI into HEIs to prepare staff, students and the curriculum for an evolving world and workplace. We will highlight the advantages of working with these technologies beyond the realm of teaching, learning and assessment by considering prompt engineering skills, industry impact, curriculum changes, and the need for staff upskilling. In contrast, not engaging strategically with Generative AI poses risks, including falling behind peers, missed opportunities and failing to ensure our graduates remain employable. The rapid evolution of AI technologies necessitates a proactive and strategic approach if we are to remain relevant.
Biological screening of herbal drugs: Introduction and Need for
Phyto-Pharmacological Screening, New Strategies for evaluating
Natural Products, In vitro evaluation techniques for Antioxidants, Antimicrobial and Anticancer drugs. In vivo evaluation techniques
for Anti-inflammatory, Antiulcer, Anticancer, Wound healing, Antidiabetic, Hepatoprotective, Cardio protective, Diuretics and
Antifertility, Toxicity studies as per OECD guidelines
Read| The latest issue of The Challenger is here! We are thrilled to announce that our school paper has qualified for the NATIONAL SCHOOLS PRESS CONFERENCE (NSPC) 2024. Thank you for your unwavering support and trust. Dive into the stories that made us stand out!
3. The C preprocessor provides several tools that are
unavailable in other high-level languages.
The programmer can use these tools to make his
program easy to read, easy to modify, portable and
more efficient.
The C Preprocessor is not a part of the compiler, but
is a separate step in the compilation process.
4.
5. The preprocessor is a program that process the code before it
basses through the computer preprocessor directivities are
placed in the source program before the main line.
In simple terms, a C Preprocessor is just a text substitution
tool and it instructs the compiler to do required pre-
processing before the actual compilation.
All preprocessor commands begin with a hash symbol (#). It
must be the first nonblank character, and for readability, a
preprocessor directive should begin in the first column.
6.
7.
8. The following section lists down all the important preprocessor directives −
Directive Description
#define Substitutes a preprocessor macro.
#include Inserts a particular header from another file.
#undef Undefines a preprocessor macro.
#ifdef Returns true if this macro is defined.
#ifndef Returns true if this macro is not defined.
#if Tests if a compile time condition is true.
#else The alternative for #if.
#elif #else and #if in one statement.
#endif Ends preprocessor conditional.
#error Prints error message on stderr.
#pragma Issues special commands to the compiler, using a standardized
method.
10. Macro substitution is a process where an identifier in a
program is replaced by a predefined string composed of one
or more identifiers.
It accomplishes this task under the direction of ‘#define’
statement. The general form is
The definition is not terminated by a semicolon. The string
may be any text, while the identifier must be a valid C name.
There are different forms of macro substitution. The most
common forms are:
Syntax: # define identifier string
11. There are different forms of macro substitutions.
The most common forms are
1. Simple macro substitution.
2. Argumented macro substitution.
3. Nested macro substitution.
12. Simple string replacement is commonly used to define
constants.
Example :
We have written all macros(identifiers) in capitals. It is a
conversion to write all macros in capitals to identify them as
symbolic constants.
It will replace all occurrences of ‘M’ with ‘5’, starting from
the line of identifier to the end of the program.
Example :
# define COUNT 100
# define CAPITAL “DELHI”
# define M 5
Total = M * value ;
Printf(“M = %dn”, M);
13. These two lines would be changed during pre-processing as
follows.
Example:
We can use a macro to define almost anything
Example:
To build a statement as follows TEST AND PRINT
The preprocessor would translate this line to
If(x<y) printf(“very good”);
#define TEST if(x<y)
#define AND
#define PRINT printf(“very good”);
Total = 5 * value ;
Printf (“M=%dn” , 5);
14. The preprocessor permits to define more useful form of define
replacements. It takes the form
Syntax:
There is no space between the macro identifier and the left
parentheses. The identifiers f1,f2,…..fn are the formal macro
arguments that are analogous to the formal arguments in a
function definition.
A macro with arguments is known as a macro call.
When a macro is called, the preprocessor substitutes the string
replacing the formal parameters with the actual parameters.
# define Identifier(f1,f2,…fn) string
15. A simple example of a macro with argument is
If the following statement appears in the program
Then the preprocessor would expand this statement as
# define CUBE(X) (x*x*x)
Volume = CUBE(side);
Volume = side * side * side;
16. Nesting Of Macros use one macro in the definition of another
macro. The Macro definitions may be nested.
Consider the following macro definitions.
The preprocessor expands each #define macro until no more
macros appear in the test. For example the last definition is
first expands into
# define SQUARE(x) (x*x)
# define CUBE(x) (SQUARE(x)*x)
# define SIXTH(x) (CUBE(x)*CUBE(x))
(SQUARE(x)*x) * (SQUARE(x) * x)
17. Since ‘SQUARE(x)’ is still a macro, it is further
expanded into
( ( x * x ) * x ) * ( (x*x)*x)
which is finally evaluated as x6.
Macro calls can be nested in much the same fashion
as function calls.
Example : #define HALF ( (x)/2.0 )
#define Y HALF( HALF(x) )
18. A defined macro can be undefined using statement
Syntax:
This is useful to restrict the definition only to a
particular part of the program.
# undef identifier
19. File Inclusion is an external file containing functions or macro
definitions can be included as a part of a program.
This is achieved by a preprocessor directive.
Syntax:
The ‘file name’ is the name of the file containing the required
definitions or functions.
At this point, the preprocessor inserts the entire contents of the
file name into the source code of the program.
When the file name is included within the (“ ”) ,then the search
for the file is made first in the current directory and then in the
standard directories.
#include “file name”
20. Alternatively this directive takes the form
Without (“ ”) in this case this file can include other files.
However a file can’t include itself.
We can make use of a definition or function contained in
anyone of these files by including them in the program as
shown below.
#include<stdio.h>
#include“shiva.c”
#define M 5
main( )
{
……………
……………
}
#include <file name>
21. Compiler Control Directives is developing large
programs, the ‘C’ pre-processor offers a feature
known as conditional compilation.
It can be used to ‘switch’ on or off a particular line
or a group of lines in a program.
22. These compiler control directives are used in different situations.
They are:
Situation 1:
This situation refers to the conditional definition of a macro. We
want to ensure that the macro TEST is always defined, irrespective
of whether it has been defined in the header file or not. This can be
achieved as follows:
DEFINE.H is the header that is supposed to contain the definition
of TEST macro.
The directive #ifndef TEST searches the definition of TEST in the
header file and if it is not defined, then all the lines between
the #ifndef and the corresponding #endif directive are executed in
the program.
#include ”DEFINE.H”
#ifndef TEST
#define TEST 1
#endif
23. Situation 2:
The main concern here is to make the program portable. This
can be achieved as shown below:
If we want to run the program on a IBM PC, we include the
directive otherwise we won’t.
NOTE:
The compiler control directives are inside the function. Care
must be taken to put the # character at column one.
#ifdef IBM_PC
{
—— code for IBM_PC
——
}
#else
{
—— code for HP machine
——
}
#endif
#define IBM_PC
24. Situation 3:
This situation is similar to the above situation and therefore
the control directives take the following form:
Group-A lines are included if the customer ABC is defined.
Otherwise, Group-B lines are included.
#idef ABC
Group–A lines
#else
Group–B lines
#endif
25. The C preprocessor also supports a more general form of test
condition - #if directive. This take the following form:
The constant-expression may be any logical expression such as:
If the result of the constant –expression is nonzero (true), then
all the statements between the #if and #endif are included for
processing ; otherwise they are skipped. The names TEST,
LEVEL , etc., may be defined as macros.
#if constant expression
{
Statement 1;
Statement 2;
——–
}
else
{
Statement 1;
Statement 2;
——–
}
#endif
TEST <=3
(LEVEL == 1|| LEVEL == 2)
MACHINE == ‘A’
26. ASNI committee has added some more preprocessor
directives to the existing list given in the table .they
are:
The ANSI standard also include two new
preprocessor operation:
#elif Provides alternative test facility.
#pragma Specifies certain instructions.
#error Stops compilation when an error occurs.
# Stringizing operator
## Token-pasting operator
27. The #elif enables us to establish an “if..else..if..”
sequence for testing multiple conditions. The
general form of use of #elif is:
Syntax:
#if expression 1
statement sequence 1
#elif expression 2
statement sequence 2
………..
………..
#elif expression N
statement sequence N
#endif
Example:
#if MACHINE == HCL
#define FILE”hcl.h”
#elif MACHINE == WIPRO
#define FILE”wipro.h”
………..
………..
#elif MACHINE == DCM
#define FILE”dcm.h”
#endif
#include FILE
28. The #pragma is an implementation oriented directive that
allows us to specify various instructions to be given to the
compiler. It takes the following form:
where , name is the name of the pragma we want.
For example, under Microsoft C,
causes loop optimization to be performed. It is ignored, if the
compiler does not recognize it.
#pragma name
#pragma loop_opt(on)
29. The #error directives is used to produce diagnostic message during
debugging. The general form is
Syntax:
When the error directive is encountered, it displays the error
message and terminates processing.
NOTE:
We have used a special processor operator defined along with if.
defined is a new addition and take a name surrounded by
parentheses. If a compiler does not support this, we can replace it
as follows:
#error error message
Example:
#id !define (FILE_G)
#error NO GRAPHICS FACILITY
# endif
#id !define by #ifndef
#id !define by #ifdef
30. An operation # called stringizing operator to be used in the
definition of macro functions.
This operator allows a formal argument within a macro
definition to be converted to a string.
Example:
• The preprocessor will convert the line - Sum(a+b);
• into - printf(“a+b” ”=%fn”,a+b);
• which is equivalent to - printf(“a+b =%fn”,a+b);
NOTE:
The ANSI standard also adjacent strings will be concatenated.
#define sum(xy) printf(xy”=%fn”),xy
main()
{
………
Sum(a+b);
……….
}
31. The token pasting operator ## defined by ANSI standard enables us to
combine two tokens within a marco definition to form a single token.
Example:
• The preprocessor transforms the statement
printf(“%f”,combine (total,sales));
• into the statement - printf(“%f”,total,sales);
• Consider another macro definition:
#define print(i) printf (“a”#i “=%f”, a##i)
• This marco will convert the statement - print(5)
into the statement - printf(“a5=%f”,a5)
#define combine (s1,s2) s1 ## s2
main()
{
…………
printf(“%f”,combine (total,sales));
…………
}