SlideShare a Scribd company logo
1 of 11
Constants
N.V.Raja Sekhar Reddy
C-Programming Tutorials
www.programming9.com
What to Discuss?
 What is a Constant ?
 Types of Constants in C
 Integer Constants
 Real Constants
 Character Constants
 String Constants
2 www.programming9.com
What is a Constant?
www.programming9.com3
 Constant is a value that cannot change during the
execution of a program.
 Like variables constants have data types.
Syntax
www.programming9.com4
const data_type variable_name;
(or) 
data_type const variable_name;
You can also define as follows
#define pi 3.14
Types of Constants in C
www.programming9.com5
 Integer Constants
 Real Constants
 Character Constants
 String Constants
Integer Constants
www.programming9.com6
 C integer constant is a decimal, octal (Value starts with 0)
or hexadecimal number (Value starts with 0x).
 Integer constants are always positive until you specify a
negative(-) sign.
Decimal
Constants
Octal Constants HexaDecimal
Constants
10 012 0xA
1024 02000 0x400
12789845 060624125 0xC32855
Example Program
www.programming9.com7
#include<stdio.h>
void main()
{
const int a=10; //Decimal
int const b= 012; //Octal
const int c=0xA; //Hexadecimal
printf(" %d n %d n %d",a,b,c);
}
OUTPUT: it prints 10 10 10 as output.
Real Constants
www.programming9.com8
 The default form of real constant is double and it must
have a decimal point. You can represent the negative
numbers in real constants. It may be in fractional form or
exponential form.
Ex: 3.45, -2.58, 0.3E-5 (equal to 0.3 x 10-5
)
Representation Value Type
0 0.0 double
6.77 6.77 double
-6.0f -6.0 float
3.1415926536L 3.1415926536 long double
Character Constants
www.programming9.com9
 Character Constants must be enclosed with in single
quotes. We use escape character along with the
character. The escape character says that it is not a
normal character and do something.
ASCII Character Symbol
Alert(bell) 'a'
Null character '0'
Backspace 'b'
Horizontal Tab 't'
New line 'n'
Vertical tab 'v'
Form Feed 'f'
Carriage Return 'r'
Single Quote '''
Double Quote '"'
Backslash ''
String Constants
www.programming9.com10
 A string constant is a sequence of characters enclosed in
a double quotes.
 Examples:
"" // Null String
"programming9" // a full string with 12 characters
"wel come" // string with 8 characters
Please Like Us…
www.programming9.com11
 www.programming9.com
 Visit us @
 https://www.facebook.com/groups/programming9dotcom
/
 https://www.facebook.com/programming9
 https://plus.google.com/100725294536794081179
 http://www.youtube.com/user/nvrajasekhar?
sub_confirmation=1

More Related Content

What's hot

structure and union
structure and unionstructure and union
structure and union
student
 
constants, variables and datatypes in C
constants, variables and datatypes in Cconstants, variables and datatypes in C
constants, variables and datatypes in C
Sahithi Naraparaju
 

What's hot (20)

Control statements in c
Control statements in cControl statements in c
Control statements in c
 
Character set of c
Character set of cCharacter set of c
Character set of c
 
RECURSION IN C
RECURSION IN C RECURSION IN C
RECURSION IN C
 
data types in C programming
data types in C programmingdata types in C programming
data types in C programming
 
Formatted input and output
Formatted input and outputFormatted input and output
Formatted input and output
 
Loops in C Programming Language
Loops in C Programming LanguageLoops in C Programming Language
Loops in C Programming Language
 
Strings
StringsStrings
Strings
 
Programming in c Arrays
Programming in c ArraysProgramming in c Arrays
Programming in c Arrays
 
structure and union
structure and unionstructure and union
structure and union
 
constants, variables and datatypes in C
constants, variables and datatypes in Cconstants, variables and datatypes in C
constants, variables and datatypes in C
 
Data Types and Variables In C Programming
Data Types and Variables In C ProgrammingData Types and Variables In C Programming
Data Types and Variables In C Programming
 
Pointers C programming
Pointers  C programmingPointers  C programming
Pointers C programming
 
Pointer in c
Pointer in cPointer in c
Pointer in c
 
Operators in C Programming
Operators in C ProgrammingOperators in C Programming
Operators in C Programming
 
Functions in c
Functions in cFunctions in c
Functions in c
 
Strings in C
Strings in CStrings in C
Strings in C
 
Data Type in C Programming
Data Type in C ProgrammingData Type in C Programming
Data Type in C Programming
 
Presentation on Function in C Programming
Presentation on Function in C ProgrammingPresentation on Function in C Programming
Presentation on Function in C Programming
 
Variables in C and C++ Language
Variables in C and C++ LanguageVariables in C and C++ Language
Variables in C and C++ Language
 
Function in C program
Function in C programFunction in C program
Function in C program
 

Viewers also liked (6)

Comments in C Programming
Comments in C ProgrammingComments in C Programming
Comments in C Programming
 
Chapter1 c programming data types, variables and constants
Chapter1 c programming   data types, variables and constantsChapter1 c programming   data types, variables and constants
Chapter1 c programming data types, variables and constants
 
C ppt
C pptC ppt
C ppt
 
INTRODUCTION TO C PROGRAMMING
INTRODUCTION TO C PROGRAMMINGINTRODUCTION TO C PROGRAMMING
INTRODUCTION TO C PROGRAMMING
 
Basics of C programming
Basics of C programmingBasics of C programming
Basics of C programming
 
Storage class in C Language
Storage class in C LanguageStorage class in C Language
Storage class in C Language
 

Similar to Constants in C Programming

Chapter 13.1.1
Chapter 13.1.1Chapter 13.1.1
Chapter 13.1.1
patcha535
 
3Arrays, Declarations, Expressions, Statements, Symbolic constant.pptx
3Arrays, Declarations, Expressions, Statements, Symbolic constant.pptx3Arrays, Declarations, Expressions, Statements, Symbolic constant.pptx
3Arrays, Declarations, Expressions, Statements, Symbolic constant.pptx
ganeshkarthy
 

Similar to Constants in C Programming (20)

Chapter 13.1.1
Chapter 13.1.1Chapter 13.1.1
Chapter 13.1.1
 
C programming tutorial
C programming tutorialC programming tutorial
C programming tutorial
 
Learn C# Programming - Variables & Constants
Learn C# Programming - Variables & ConstantsLearn C# Programming - Variables & Constants
Learn C# Programming - Variables & Constants
 
PROGRAMMING IN C - Inroduction.pptx
PROGRAMMING IN C - Inroduction.pptxPROGRAMMING IN C - Inroduction.pptx
PROGRAMMING IN C - Inroduction.pptx
 
Introduction
IntroductionIntroduction
Introduction
 
Fundamentals of C Programming Language
Fundamentals of C Programming LanguageFundamentals of C Programming Language
Fundamentals of C Programming Language
 
Constants and variables in c programming
Constants and variables in c programmingConstants and variables in c programming
Constants and variables in c programming
 
3Arrays, Declarations, Expressions, Statements, Symbolic constant.pptx
3Arrays, Declarations, Expressions, Statements, Symbolic constant.pptx3Arrays, Declarations, Expressions, Statements, Symbolic constant.pptx
3Arrays, Declarations, Expressions, Statements, Symbolic constant.pptx
 
Constants Variables Datatypes by Mrs. Sowmya Jyothi
Constants Variables Datatypes by Mrs. Sowmya JyothiConstants Variables Datatypes by Mrs. Sowmya Jyothi
Constants Variables Datatypes by Mrs. Sowmya Jyothi
 
Getting started with c++
Getting started with c++Getting started with c++
Getting started with c++
 
Getting started with c++
Getting started with c++Getting started with c++
Getting started with c++
 
C programing Tutorial
C programing TutorialC programing Tutorial
C programing Tutorial
 
Mql4 manual
Mql4 manualMql4 manual
Mql4 manual
 
Mql4 manual
Mql4 manualMql4 manual
Mql4 manual
 
Fundamentals of c programming
Fundamentals of c programmingFundamentals of c programming
Fundamentals of c programming
 
Data types
Data typesData types
Data types
 
Java Object Orientend Programming 1.pptx
Java Object Orientend Programming 1.pptxJava Object Orientend Programming 1.pptx
Java Object Orientend Programming 1.pptx
 
COM1407: Variables and Data Types
COM1407: Variables and Data Types COM1407: Variables and Data Types
COM1407: Variables and Data Types
 
Chapter 2 : Balagurusamy_ Programming ANsI in C
Chapter 2 :  Balagurusamy_ Programming ANsI in CChapter 2 :  Balagurusamy_ Programming ANsI in C
Chapter 2 : Balagurusamy_ Programming ANsI in C
 
PSPC--UNIT-2.pdf
PSPC--UNIT-2.pdfPSPC--UNIT-2.pdf
PSPC--UNIT-2.pdf
 

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
 
Russian Escort Service in Delhi 11k Hotel Foreigner Russian Call Girls in Delhi
Russian Escort Service in Delhi 11k Hotel Foreigner Russian Call Girls in DelhiRussian Escort Service in Delhi 11k Hotel Foreigner Russian Call Girls in Delhi
Russian Escort Service in Delhi 11k Hotel Foreigner Russian Call Girls in Delhi
kauryashika82
 
Jual Obat Aborsi Hongkong ( Asli No.1 ) 085657271886 Obat Penggugur Kandungan...
Jual Obat Aborsi Hongkong ( Asli No.1 ) 085657271886 Obat Penggugur Kandungan...Jual Obat Aborsi Hongkong ( Asli No.1 ) 085657271886 Obat Penggugur Kandungan...
Jual Obat Aborsi Hongkong ( Asli No.1 ) 085657271886 Obat Penggugur Kandungan...
ZurliaSoop
 

Recently uploaded (20)

Third Battle of Panipat detailed notes.pptx
Third Battle of Panipat detailed notes.pptxThird Battle of Panipat detailed notes.pptx
Third Battle of Panipat detailed notes.pptx
 
Python Notes for mca i year students osmania university.docx
Python Notes for mca i year students osmania university.docxPython Notes for mca i year students osmania university.docx
Python Notes for mca i year students osmania university.docx
 
Mehran University Newsletter Vol-X, Issue-I, 2024
Mehran University Newsletter Vol-X, Issue-I, 2024Mehran University Newsletter Vol-X, Issue-I, 2024
Mehran University Newsletter Vol-X, Issue-I, 2024
 
microwave assisted reaction. General introduction
microwave assisted reaction. General introductionmicrowave assisted reaction. General introduction
microwave assisted reaction. General introduction
 
SOC 101 Demonstration of Learning Presentation
SOC 101 Demonstration of Learning PresentationSOC 101 Demonstration of Learning Presentation
SOC 101 Demonstration of Learning Presentation
 
TỔNG ÔN TẬP THI VÀO LỚP 10 MÔN TIẾNG ANH NĂM HỌC 2023 - 2024 CÓ ĐÁP ÁN (NGỮ Â...
TỔNG ÔN TẬP THI VÀO LỚP 10 MÔN TIẾNG ANH NĂM HỌC 2023 - 2024 CÓ ĐÁP ÁN (NGỮ Â...TỔNG ÔN TẬP THI VÀO LỚP 10 MÔN TIẾNG ANH NĂM HỌC 2023 - 2024 CÓ ĐÁP ÁN (NGỮ Â...
TỔNG ÔN TẬP THI VÀO LỚP 10 MÔN TIẾNG ANH NĂM HỌC 2023 - 2024 CÓ ĐÁP ÁN (NGỮ Â...
 
Grant Readiness 101 TechSoup and Remy Consulting
Grant Readiness 101 TechSoup and Remy ConsultingGrant Readiness 101 TechSoup and Remy Consulting
Grant Readiness 101 TechSoup and Remy Consulting
 
How to Give a Domain for a Field in Odoo 17
How to Give a Domain for a Field in Odoo 17How to Give a Domain for a Field in Odoo 17
How to Give a Domain for a Field in Odoo 17
 
On National Teacher Day, meet the 2024-25 Kenan Fellows
On National Teacher Day, meet the 2024-25 Kenan FellowsOn National Teacher Day, meet the 2024-25 Kenan Fellows
On National Teacher Day, meet the 2024-25 Kenan Fellows
 
2024-NATIONAL-LEARNING-CAMP-AND-OTHER.pptx
2024-NATIONAL-LEARNING-CAMP-AND-OTHER.pptx2024-NATIONAL-LEARNING-CAMP-AND-OTHER.pptx
2024-NATIONAL-LEARNING-CAMP-AND-OTHER.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
 
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
 
Making communications land - Are they received and understood as intended? we...
Making communications land - Are they received and understood as intended? we...Making communications land - Are they received and understood as intended? we...
Making communications land - Are they received and understood as intended? we...
 
Russian Escort Service in Delhi 11k Hotel Foreigner Russian Call Girls in Delhi
Russian Escort Service in Delhi 11k Hotel Foreigner Russian Call Girls in DelhiRussian Escort Service in Delhi 11k Hotel Foreigner Russian Call Girls in Delhi
Russian Escort Service in Delhi 11k Hotel Foreigner Russian Call Girls in Delhi
 
Kodo Millet PPT made by Ghanshyam bairwa college of Agriculture kumher bhara...
Kodo Millet  PPT made by Ghanshyam bairwa college of Agriculture kumher bhara...Kodo Millet  PPT made by Ghanshyam bairwa college of Agriculture kumher bhara...
Kodo Millet PPT made by Ghanshyam bairwa college of Agriculture kumher bhara...
 
Application orientated numerical on hev.ppt
Application orientated numerical on hev.pptApplication orientated numerical on hev.ppt
Application orientated numerical on hev.ppt
 
Jual Obat Aborsi Hongkong ( Asli No.1 ) 085657271886 Obat Penggugur Kandungan...
Jual Obat Aborsi Hongkong ( Asli No.1 ) 085657271886 Obat Penggugur Kandungan...Jual Obat Aborsi Hongkong ( Asli No.1 ) 085657271886 Obat Penggugur Kandungan...
Jual Obat Aborsi Hongkong ( Asli No.1 ) 085657271886 Obat Penggugur Kandungan...
 
Sociology 101 Demonstration of Learning Exhibit
Sociology 101 Demonstration of Learning ExhibitSociology 101 Demonstration of Learning Exhibit
Sociology 101 Demonstration of Learning Exhibit
 
Unit-IV; Professional Sales Representative (PSR).pptx
Unit-IV; Professional Sales Representative (PSR).pptxUnit-IV; Professional Sales Representative (PSR).pptx
Unit-IV; Professional Sales Representative (PSR).pptx
 
How to Create and Manage Wizard in Odoo 17
How to Create and Manage Wizard in Odoo 17How to Create and Manage Wizard in Odoo 17
How to Create and Manage Wizard in Odoo 17
 

Constants in C Programming

  • 1. Constants N.V.Raja Sekhar Reddy C-Programming Tutorials www.programming9.com
  • 2. What to Discuss?  What is a Constant ?  Types of Constants in C  Integer Constants  Real Constants  Character Constants  String Constants 2 www.programming9.com
  • 3. What is a Constant? www.programming9.com3  Constant is a value that cannot change during the execution of a program.  Like variables constants have data types.
  • 4. Syntax www.programming9.com4 const data_type variable_name; (or)  data_type const variable_name; You can also define as follows #define pi 3.14
  • 5. Types of Constants in C www.programming9.com5  Integer Constants  Real Constants  Character Constants  String Constants
  • 6. Integer Constants www.programming9.com6  C integer constant is a decimal, octal (Value starts with 0) or hexadecimal number (Value starts with 0x).  Integer constants are always positive until you specify a negative(-) sign. Decimal Constants Octal Constants HexaDecimal Constants 10 012 0xA 1024 02000 0x400 12789845 060624125 0xC32855
  • 7. Example Program www.programming9.com7 #include<stdio.h> void main() { const int a=10; //Decimal int const b= 012; //Octal const int c=0xA; //Hexadecimal printf(" %d n %d n %d",a,b,c); } OUTPUT: it prints 10 10 10 as output.
  • 8. Real Constants www.programming9.com8  The default form of real constant is double and it must have a decimal point. You can represent the negative numbers in real constants. It may be in fractional form or exponential form. Ex: 3.45, -2.58, 0.3E-5 (equal to 0.3 x 10-5 ) Representation Value Type 0 0.0 double 6.77 6.77 double -6.0f -6.0 float 3.1415926536L 3.1415926536 long double
  • 9. Character Constants www.programming9.com9  Character Constants must be enclosed with in single quotes. We use escape character along with the character. The escape character says that it is not a normal character and do something. ASCII Character Symbol Alert(bell) 'a' Null character '0' Backspace 'b' Horizontal Tab 't' New line 'n' Vertical tab 'v' Form Feed 'f' Carriage Return 'r' Single Quote ''' Double Quote '"' Backslash ''
  • 10. String Constants www.programming9.com10  A string constant is a sequence of characters enclosed in a double quotes.  Examples: "" // Null String "programming9" // a full string with 12 characters "wel come" // string with 8 characters
  • 11. Please Like Us… www.programming9.com11  www.programming9.com  Visit us @  https://www.facebook.com/groups/programming9dotcom /  https://www.facebook.com/programming9  https://plus.google.com/100725294536794081179  http://www.youtube.com/user/nvrajasekhar? sub_confirmation=1