• Preprocessor are commands executed by C
Preprocessor before the program is assigned
to the compiler for compilation.
• Preprocessor directives appear at the starting
of the program.
• It is also called as CPP.
#include
• This is used to include header files in the link
section area containing the functions to be
used in a program.
#include<stdio.h>
This includes standard input output (stdio)
header files of include subdirectory from a C
directory.
• To compile a portion of program conditionally,
then these directives are used.
#ifdef(MAX)
#define MIN 20
#else
#define MAX 100
#define MIN 20
#endif
#if, #elif
• These are used when there is branched
conditions or nested conditions.
Ex:
#if code==30
printf(“color is red”);
#elif code==40
printf(“code is blue”);
#endif
#undef
• This is used to
undefine a
macro which
was earlier
defined using
#define
statement.
#pragma, ##
• Pragma is used to
write assembly
language
statements into C
program.
• ## is used to
concatenate the
items in the C
language.
Input/ output statements
• Input and output functions are collectively
known as standard I/O library functions.
• These statements deals with the console
input/output function(input from computer
and output on monitor), so called as console
input/output functions.
• Two types of I/O functions are:
1. unformatted I/O 2. formatted I/O
• 1. getchar() : an input function to read a single
character.
Syntax: v = getchar();
Ex: char m;
m=getchar();
2. putchar() : an output function to display a
single character on screen.
Syntax: putchar(v);
Ex: char m;
putchar(m);
3. gets() : an input function used to read a string from a
keyboard.
Syntax: gets(v);
Ex: char m[10];
gets(m);
4. puts() : an output function used to display gets()
inputted string on the screen.
Syntax: puts(s); or puts(“text”);
Ex: char name[20];
puts(“enter any name”);
gets(name);
puts(“the entered name is”);
puts(name);
Output:
Enter any name
Preeti
The entered name is
Preeti
5. getch() : an input function that reads a single
character. In this, a character data read by this
function is directly assigned to a variable. This even
maintains output on the screen. Also, when
character is typed ,it is not visible on the screen.
Syntax: v=getch();
Ex: char x
puts(“enter any character”);
x=getch();
puts(“entered character is”);
putchar(x);
getch();
Output:
Enter any character
Entered character is
g
6. getche() : when you type a character data from the
keyboard it will be visible on the screen.
Syntax: v=getche();
Ex: char x
puts(“enter any character”);
x=getche();
puts(“entered character is”);
putchar(x);
getche();
Output:
Enter any character
g
Entered character is
g
• It refers to an input/ output data.
• Two types are:
1. scanf() 2. printf()
1. scanf()
This is an input function. It is used to read a mixed type
of data.
Syntax: scanf(“control strings”, arg1,arg2,….argn);
Or
scanf(“control strings”,&v1,&v2….&vn);
Control strings have some format code for
different data types as follows:
Ex: int a;
scanf(“%d”,&a);
Format code Meaning
%c To read single character
%d To read a signed decimal integer
%f To read a float value
%i To read an integer(octal, decimal, hexadecimal)
%x To read a hexadecimal integer only
%u To read pointers
%s To read a string
2. printf() : This is an output function. It is used to
display text message and a mixed type of data on
the screen.
Syntax: printf(“control strings”,v1,v2….vn);
Or
printf(“message line or text line”);
Format code Meaning
%c To print single character
%d To print a signed decimal integer
%f To print a float
%x To print a hexadecimal integer only
%u To print unsigned integers
%s To print a string
• Ex:
int a;
float b;
printf(“enter the value”);
scanf(“%d%f”,&a,&b);
printf(“the data is”);
printf(“%d%f”,a,b);
Output:
enter the value
5 6.0
the data is
5 6.0

C preprocesor

  • 1.
    • Preprocessor arecommands executed by C Preprocessor before the program is assigned to the compiler for compilation. • Preprocessor directives appear at the starting of the program. • It is also called as CPP.
  • 3.
    #include • This isused to include header files in the link section area containing the functions to be used in a program. #include<stdio.h> This includes standard input output (stdio) header files of include subdirectory from a C directory.
  • 4.
    • To compilea portion of program conditionally, then these directives are used. #ifdef(MAX) #define MIN 20 #else #define MAX 100 #define MIN 20 #endif
  • 5.
    #if, #elif • Theseare used when there is branched conditions or nested conditions. Ex: #if code==30 printf(“color is red”); #elif code==40 printf(“code is blue”); #endif
  • 6.
    #undef • This isused to undefine a macro which was earlier defined using #define statement. #pragma, ## • Pragma is used to write assembly language statements into C program. • ## is used to concatenate the items in the C language.
  • 7.
    Input/ output statements •Input and output functions are collectively known as standard I/O library functions. • These statements deals with the console input/output function(input from computer and output on monitor), so called as console input/output functions. • Two types of I/O functions are: 1. unformatted I/O 2. formatted I/O
  • 8.
    • 1. getchar(): an input function to read a single character. Syntax: v = getchar(); Ex: char m; m=getchar(); 2. putchar() : an output function to display a single character on screen. Syntax: putchar(v); Ex: char m; putchar(m);
  • 9.
    3. gets() :an input function used to read a string from a keyboard. Syntax: gets(v); Ex: char m[10]; gets(m); 4. puts() : an output function used to display gets() inputted string on the screen. Syntax: puts(s); or puts(“text”); Ex: char name[20]; puts(“enter any name”); gets(name); puts(“the entered name is”); puts(name); Output: Enter any name Preeti The entered name is Preeti
  • 10.
    5. getch() :an input function that reads a single character. In this, a character data read by this function is directly assigned to a variable. This even maintains output on the screen. Also, when character is typed ,it is not visible on the screen. Syntax: v=getch(); Ex: char x puts(“enter any character”); x=getch(); puts(“entered character is”); putchar(x); getch(); Output: Enter any character Entered character is g
  • 11.
    6. getche() :when you type a character data from the keyboard it will be visible on the screen. Syntax: v=getche(); Ex: char x puts(“enter any character”); x=getche(); puts(“entered character is”); putchar(x); getche(); Output: Enter any character g Entered character is g
  • 12.
    • It refersto an input/ output data. • Two types are: 1. scanf() 2. printf() 1. scanf() This is an input function. It is used to read a mixed type of data. Syntax: scanf(“control strings”, arg1,arg2,….argn); Or scanf(“control strings”,&v1,&v2….&vn);
  • 13.
    Control strings havesome format code for different data types as follows: Ex: int a; scanf(“%d”,&a); Format code Meaning %c To read single character %d To read a signed decimal integer %f To read a float value %i To read an integer(octal, decimal, hexadecimal) %x To read a hexadecimal integer only %u To read pointers %s To read a string
  • 14.
    2. printf() :This is an output function. It is used to display text message and a mixed type of data on the screen. Syntax: printf(“control strings”,v1,v2….vn); Or printf(“message line or text line”); Format code Meaning %c To print single character %d To print a signed decimal integer %f To print a float %x To print a hexadecimal integer only %u To print unsigned integers %s To print a string
  • 15.
    • Ex: int a; floatb; printf(“enter the value”); scanf(“%d%f”,&a,&b); printf(“the data is”); printf(“%d%f”,a,b); Output: enter the value 5 6.0 the data is 5 6.0