Documente Academic
Documente Profesional
Documente Cultură
COM
HOME
C TUTORIAL
C INTERVIEW Q&A
SQL TUTORIAL
JAVA TUTORIAL
JSP
XML
C PROGRAMMING TUTORIAL
C - LANGUAGE HISTORY
C - PROGRAMMING BASICS
C - DATA TYPES
C - CONSTANT
C - VARIABLE
C - TYPE QUALIFIERS
C - ARRAY
C - STRING
C - POINTER
C - FUNCTION
C - ARITHMETIC FUNCTIONS
C - MISCELLANEOUS FUNCTIONS
C - STRUCTURE
C - TYPEDEF
C - UNION
C - PREPROCESSOR DIRECTIVES
C - FILE HANDLING
C Preprocessor directives
PREV
NEXT
C PREPROCESSOR DIRECTIVES:
Preprocesso
r
Syntax/Description
Macro
Syntax: #define
This macro defines constant value and can be
any of the basic data types.
Header file
inclusion
Conditional
compilation
Other
directives
A program in C language involves into different processes. Below diagram will help
you to understand all the processes that a C program comes across.
There are 4 regions of memory which are created by a compiled C program. They
are,
1.
First region This is the memory region which holds the executable code of
the program.
2.
2nd region In this memory region, global variables are stored.
3.
3rd region stack
4.
4th region heap
DO YOU KNOW DIFFERENCE BETWEEN STACK & HEAP MEMORY IN C
LANGUAGE?
Stack
Heap
Heap is a memory
region which is used by
dynamic memory
allocation functions at
run time.
Linked list is an
example which uses
heap memory.
DO YOU KNOW DIFFERENCE BETWEEN COMPILERS VS INTERPRETERS IN
C LANGUAGE?
Compilers
Compiler reads the entire
source code of the program
and converts it into binary
code. This process is called
compilation.
Binary code is also referred
as machine code, executable,
and object code.
Interpreters
#define This macro defines constant value and can be any of the basic data
types.
1
2
3
4
5
6
7
#include <stdio.h>
#define
#define
#define
#define
#define
height 100
number 3.14
letter 'A'
letter_sequence "ABC"
backslash_char '\?'
8
9 void main()
10 {
11 printf("value
12 printf("value
13 printf("value
14 printf("value
15 printf("value
16
17 }
of
of
of
of
of
OUTPUT:
value
value
value
value
value
of
of
of
of
of
height : 100
number : 3.140000
letter : A
letter_sequence : ABC
backslash_char : ?
1 #include <stdio.h>
2 #define RAJU 100
3
4 int main()
5 {
6
#ifdef RAJU
7
printf("RAJU is defined. So, this line will be added in " \
8
"this C file\n");
9
#else
10 printf("RAJU is not defined\n");
11 #endif
12 return 0;
13 }
OUTPUT:
1 #include <stdio.h>
2 #define RAJU 100
3 int main()
4 {
5
#ifndef SELVA
6
{
7
printf("SELVA is not defined. So, now we are going to " \
8
"define here\n");
9
#define SELVA 300
10 }
11 #else
12 printf("SELVA is already defined in the program);
13
14 #endif
15 return 0;
16
17 }
OUTPUT:
Otherwise, else clause statement is included in source file for compilation and
execution.
C
1
2
3
4
5
6
7
#include <stdio.h>
#define a 100
int main()
{
#if (a==100)
printf("This line will be added in this C file since " \
"a \= 100\n");
8
9
10
11
12
13 }
#else
printf("This line will be added in this C file since " \
"a is not equal to 100\n");
#endif
return 0;
OUTPUT:
1 #include <stdio.h>
2
3 #define height 100
4 void main()
5 {
6
printf("First defined value for height : %d\n",height);
7
#undef height
// undefining variable
8
#define height 600
// redefining the same for new value
9
printf("value of height after undef \& redefine:%d",height);
10 }
OUTPUT:
1 #include <stdio.h>
2
3 void function1( );
4 void function2( );
5
6 #pragma startup function1
7 #pragma exit function2
8
9 int main( )
10 {
11 printf ( "\n Now we are in main function" ) ;
12 return 0;
13 }
14
15 void function1( )
16 {
17 printf("\nFunction1 is called before main function call");
18 }
19
20 void function2( )
21 {
22 printf ( "\nFunction2 is called just before end of " \
23
"main function" ) ;"
24 }
OUTPUT:
Pragma command
Description
#Pragma startup
<function_name_1>
#Pragma exit
<function_name_2>
PREV
NEXT
Share this C, SQL, Java programming, JSP & XML tutorial website