SlideShare a Scribd company logo
1 of 13
C Programming Language
Defining Constants and Unformatted Input
Output Functions
Dr.G.Jasmine Beulah
Defining Constants
There are two simple ways in C to define
constants:
1. Using #define preprocessor.
2. Using const keyword.
1.The #define Preprocessor
This is how to use #define preprocessor to
define a constant:
#define identifier value
Example
#include <stdio.h>
#define LENGTH 10
#define WIDTH 5
#define NEWLINE 'n'
void main()
{
int area;
area = LENGTH * WIDTH;
printf("value of area : %d", area);
printf("%c", NEWLINE);
}
When the above code is compiled and executed,
it produces following result:
value of area : 50
2.The const Keyword
The const prefix can be used to declare
constants with a specific type as follows:
const datatype identifier = value;
const int len=5;
const float pi=3.14;
Example
#include <stdio.h>
void main()
{
const int LENGTH = 10;
const int WIDTH = 5;
const char NEWLINE = 'n';
int area;
area = LENGTH * WIDTH;
printf("value of area : %d", area);
printf("%c", NEWLINE);
}
OUTPUT
50
Unformatted Input Output Functions
getchar()- int getchar(void)
 This function reads the next available character from the screen and returns it as
an integer.
 This function reads only single character at a time.
 This method can be used in the loop in case you want to read more than one
characters from the screen.
putchar()-int putchar(int c)
 This function puts the passed character on the screen and returns the same
character.
 This function puts only single character at a time.
 This method can be used in the loop in case you want to display more than one
character on the screen.
getchar(),putchar()-Example
#include <stdio.h>
void main( )
{
int c;
printf( "Enter a value :");
c = getchar( );
printf( "nYou entered: ");
putchar( c );
}
getch(),putch(),getche()
getch() and putch() is also used to input and
output a single character.
getche()echoes the input character but
getch()doesnt echo the input character.
getch() reads a single character from keyboard and displays the
entered character without using enter key , it doesnot buffer any.
getche() reads a single character from the keyboard and displays
immediately on output screen without waiting for enter key.
gets(), puts() functions
gets()- char *gets(char *s)
This function reads a line (string) from stdin into the buffer pointed to by s until either
a terminating newline or EOF.
puts()-int puts(const char *s)
This function writes the string s and a trailing newline to stdout.
#include <stdio.h>
void main( )
{
char str[100];
printf( "Enter a value :");
gets( str );
printf( "nYou entered: ");
puts( str );
}
gets(), puts() -Example

More Related Content

Similar to Constants and Unformatted Input Output Functions.pptx

Ch2 introduction to c
Ch2 introduction to cCh2 introduction to c
Ch2 introduction to c
Hattori Sidek
 
C++: Constructor, Copy Constructor and Assignment operator
C++: Constructor, Copy Constructor and Assignment operatorC++: Constructor, Copy Constructor and Assignment operator
C++: Constructor, Copy Constructor and Assignment operator
Jussi Pohjolainen
 

Similar to Constants and Unformatted Input Output Functions.pptx (20)

Concepts of C [Module 2]
Concepts of C [Module 2]Concepts of C [Module 2]
Concepts of C [Module 2]
 
C language
C languageC language
C language
 
Assignment c programming
Assignment c programmingAssignment c programming
Assignment c programming
 
Input And Output
 Input And Output Input And Output
Input And Output
 
C programing Tutorial
C programing TutorialC programing Tutorial
C programing Tutorial
 
First c program
First c programFirst c program
First c program
 
C++ and OOPS Crash Course by ACM DBIT | Grejo Joby
C++ and OOPS Crash Course by ACM DBIT | Grejo JobyC++ and OOPS Crash Course by ACM DBIT | Grejo Joby
C++ and OOPS Crash Course by ACM DBIT | Grejo Joby
 
Programming Fundamentals lecture 5
Programming Fundamentals lecture 5Programming Fundamentals lecture 5
Programming Fundamentals lecture 5
 
CPU INPUT OUTPUT
CPU INPUT OUTPUT CPU INPUT OUTPUT
CPU INPUT OUTPUT
 
Ch2 introduction to c
Ch2 introduction to cCh2 introduction to c
Ch2 introduction to c
 
the refernce of programming C notes ppt.pptx
the refernce of programming C notes ppt.pptxthe refernce of programming C notes ppt.pptx
the refernce of programming C notes ppt.pptx
 
C programming(part 3)
C programming(part 3)C programming(part 3)
C programming(part 3)
 
Pointers in C Language
Pointers in C LanguagePointers in C Language
Pointers in C Language
 
C++: Constructor, Copy Constructor and Assignment operator
C++: Constructor, Copy Constructor and Assignment operatorC++: Constructor, Copy Constructor and Assignment operator
C++: Constructor, Copy Constructor and Assignment operator
 
C preprocesor
C preprocesorC preprocesor
C preprocesor
 
Core programming in c
Core programming in cCore programming in c
Core programming in c
 
2. Data, Operators, IO.ppt
2. Data, Operators, IO.ppt2. Data, Operators, IO.ppt
2. Data, Operators, IO.ppt
 
String Manipulation Function and Header File Functions
String Manipulation Function and Header File FunctionsString Manipulation Function and Header File Functions
String Manipulation Function and Header File Functions
 
Lec 10
Lec 10Lec 10
Lec 10
 
C++ L09-Classes Part2
C++ L09-Classes Part2C++ L09-Classes Part2
C++ L09-Classes Part2
 

More from DrJasmineBeulahG (9)

File Handling in C.pptx
File Handling in C.pptxFile Handling in C.pptx
File Handling in C.pptx
 
Software Testing.pptx
Software Testing.pptxSoftware Testing.pptx
Software Testing.pptx
 
Software Process Model.ppt
Software Process Model.pptSoftware Process Model.ppt
Software Process Model.ppt
 
NumPy.pptx
NumPy.pptxNumPy.pptx
NumPy.pptx
 
Exception Handling in Python
Exception Handling in PythonException Handling in Python
Exception Handling in Python
 
STUDENT DETAILS DATABASE.pptx
STUDENT DETAILS DATABASE.pptxSTUDENT DETAILS DATABASE.pptx
STUDENT DETAILS DATABASE.pptx
 
Selection Sort.pptx
Selection Sort.pptxSelection Sort.pptx
Selection Sort.pptx
 
Structures
StructuresStructures
Structures
 
Arrays
ArraysArrays
Arrays
 

Recently uploaded

1029-Danh muc Sach Giao Khoa khoi 6.pdf
1029-Danh muc Sach Giao Khoa khoi  6.pdf1029-Danh muc Sach Giao Khoa khoi  6.pdf
1029-Danh muc Sach Giao Khoa khoi 6.pdf
QucHHunhnh
 
The basics of sentences session 2pptx copy.pptx
The basics of sentences session 2pptx copy.pptxThe basics of sentences session 2pptx copy.pptx
The basics of sentences session 2pptx copy.pptx
heathfieldcps1
 
Beyond the EU: DORA and NIS 2 Directive's Global Impact
Beyond the EU: DORA and NIS 2 Directive's Global ImpactBeyond the EU: DORA and NIS 2 Directive's Global Impact
Beyond the EU: DORA and NIS 2 Directive's Global Impact
PECB
 
Activity 01 - Artificial Culture (1).pdf
Activity 01 - Artificial Culture (1).pdfActivity 01 - Artificial Culture (1).pdf
Activity 01 - Artificial Culture (1).pdf
ciinovamais
 

Recently uploaded (20)

Z Score,T Score, Percential Rank and Box Plot Graph
Z Score,T Score, Percential Rank and Box Plot GraphZ Score,T Score, Percential Rank and Box Plot Graph
Z Score,T Score, Percential Rank and Box Plot Graph
 
Explore beautiful and ugly buildings. Mathematics helps us create beautiful d...
Explore beautiful and ugly buildings. Mathematics helps us create beautiful d...Explore beautiful and ugly buildings. Mathematics helps us create beautiful d...
Explore beautiful and ugly buildings. Mathematics helps us create beautiful d...
 
Mixin Classes in Odoo 17 How to Extend Models Using Mixin Classes
Mixin Classes in Odoo 17  How to Extend Models Using Mixin ClassesMixin Classes in Odoo 17  How to Extend Models Using Mixin Classes
Mixin Classes in Odoo 17 How to Extend Models Using Mixin Classes
 
Unit-V; Pricing (Pharma Marketing Management).pptx
Unit-V; Pricing (Pharma Marketing Management).pptxUnit-V; Pricing (Pharma Marketing Management).pptx
Unit-V; Pricing (Pharma Marketing Management).pptx
 
1029-Danh muc Sach Giao Khoa khoi 6.pdf
1029-Danh muc Sach Giao Khoa khoi  6.pdf1029-Danh muc Sach Giao Khoa khoi  6.pdf
1029-Danh muc Sach Giao Khoa khoi 6.pdf
 
Basic Civil Engineering first year Notes- Chapter 4 Building.pptx
Basic Civil Engineering first year Notes- Chapter 4 Building.pptxBasic Civil Engineering first year Notes- Chapter 4 Building.pptx
Basic Civil Engineering first year Notes- Chapter 4 Building.pptx
 
SOCIAL AND HISTORICAL CONTEXT - LFTVD.pptx
SOCIAL AND HISTORICAL CONTEXT - LFTVD.pptxSOCIAL AND HISTORICAL CONTEXT - LFTVD.pptx
SOCIAL AND HISTORICAL CONTEXT - LFTVD.pptx
 
Nutritional Needs Presentation - HLTH 104
Nutritional Needs Presentation - HLTH 104Nutritional Needs Presentation - HLTH 104
Nutritional Needs Presentation - HLTH 104
 
The basics of sentences session 2pptx copy.pptx
The basics of sentences session 2pptx copy.pptxThe basics of sentences session 2pptx copy.pptx
The basics of sentences session 2pptx copy.pptx
 
Beyond the EU: DORA and NIS 2 Directive's Global Impact
Beyond the EU: DORA and NIS 2 Directive's Global ImpactBeyond the EU: DORA and NIS 2 Directive's Global Impact
Beyond the EU: DORA and NIS 2 Directive's Global Impact
 
This PowerPoint helps students to consider the concept of infinity.
This PowerPoint helps students to consider the concept of infinity.This PowerPoint helps students to consider the concept of infinity.
This PowerPoint helps students to consider the concept of infinity.
 
Key note speaker Neum_Admir Softic_ENG.pdf
Key note speaker Neum_Admir Softic_ENG.pdfKey note speaker Neum_Admir Softic_ENG.pdf
Key note speaker Neum_Admir Softic_ENG.pdf
 
Código Creativo y Arte de Software | Unidad 1
Código Creativo y Arte de Software | Unidad 1Código Creativo y Arte de Software | Unidad 1
Código Creativo y Arte de Software | Unidad 1
 
Web & Social Media Analytics Previous Year Question Paper.pdf
Web & Social Media Analytics Previous Year Question Paper.pdfWeb & Social Media Analytics Previous Year Question Paper.pdf
Web & Social Media Analytics Previous Year Question Paper.pdf
 
Presentation by Andreas Schleicher Tackling the School Absenteeism Crisis 30 ...
Presentation by Andreas Schleicher Tackling the School Absenteeism Crisis 30 ...Presentation by Andreas Schleicher Tackling the School Absenteeism Crisis 30 ...
Presentation by Andreas Schleicher Tackling the School Absenteeism Crisis 30 ...
 
microwave assisted reaction. General introduction
microwave assisted reaction. General introductionmicrowave assisted reaction. General introduction
microwave assisted reaction. General introduction
 
Application orientated numerical on hev.ppt
Application orientated numerical on hev.pptApplication orientated numerical on hev.ppt
Application orientated numerical on hev.ppt
 
psychiatric nursing HISTORY COLLECTION .docx
psychiatric  nursing HISTORY  COLLECTION  .docxpsychiatric  nursing HISTORY  COLLECTION  .docx
psychiatric nursing HISTORY COLLECTION .docx
 
PROCESS RECORDING FORMAT.docx
PROCESS      RECORDING        FORMAT.docxPROCESS      RECORDING        FORMAT.docx
PROCESS RECORDING FORMAT.docx
 
Activity 01 - Artificial Culture (1).pdf
Activity 01 - Artificial Culture (1).pdfActivity 01 - Artificial Culture (1).pdf
Activity 01 - Artificial Culture (1).pdf
 

Constants and Unformatted Input Output Functions.pptx

  • 1. C Programming Language Defining Constants and Unformatted Input Output Functions Dr.G.Jasmine Beulah
  • 2. Defining Constants There are two simple ways in C to define constants: 1. Using #define preprocessor. 2. Using const keyword.
  • 3. 1.The #define Preprocessor This is how to use #define preprocessor to define a constant: #define identifier value
  • 4. Example #include <stdio.h> #define LENGTH 10 #define WIDTH 5 #define NEWLINE 'n' void main() { int area; area = LENGTH * WIDTH; printf("value of area : %d", area); printf("%c", NEWLINE); }
  • 5. When the above code is compiled and executed, it produces following result: value of area : 50
  • 6. 2.The const Keyword The const prefix can be used to declare constants with a specific type as follows: const datatype identifier = value; const int len=5; const float pi=3.14;
  • 7. Example #include <stdio.h> void main() { const int LENGTH = 10; const int WIDTH = 5; const char NEWLINE = 'n'; int area; area = LENGTH * WIDTH; printf("value of area : %d", area); printf("%c", NEWLINE); }
  • 9. Unformatted Input Output Functions getchar()- int getchar(void)  This function reads the next available character from the screen and returns it as an integer.  This function reads only single character at a time.  This method can be used in the loop in case you want to read more than one characters from the screen. putchar()-int putchar(int c)  This function puts the passed character on the screen and returns the same character.  This function puts only single character at a time.  This method can be used in the loop in case you want to display more than one character on the screen.
  • 10. getchar(),putchar()-Example #include <stdio.h> void main( ) { int c; printf( "Enter a value :"); c = getchar( ); printf( "nYou entered: "); putchar( c ); }
  • 11. getch(),putch(),getche() getch() and putch() is also used to input and output a single character. getche()echoes the input character but getch()doesnt echo the input character. getch() reads a single character from keyboard and displays the entered character without using enter key , it doesnot buffer any. getche() reads a single character from the keyboard and displays immediately on output screen without waiting for enter key.
  • 12. gets(), puts() functions gets()- char *gets(char *s) This function reads a line (string) from stdin into the buffer pointed to by s until either a terminating newline or EOF. puts()-int puts(const char *s) This function writes the string s and a trailing newline to stdout.
  • 13. #include <stdio.h> void main( ) { char str[100]; printf( "Enter a value :"); gets( str ); printf( "nYou entered: "); puts( str ); } gets(), puts() -Example