SlideShare a Scribd company logo
6
Most read
8
Most read
9
Most read
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

PPT
constants, variables and datatypes in C
PPT
Variables in C Programming
PPTX
Data Type in C Programming
PPTX
Data types in C
PPT
C program
PPTX
C keywords and identifiers
PPTX
Operators and expressions in c language
PPT
RECURSION IN C
constants, variables and datatypes in C
Variables in C Programming
Data Type in C Programming
Data types in C
C program
C keywords and identifiers
Operators and expressions in c language
RECURSION IN C

What's hot (20)

PPTX
Data types in C
PPTX
PPTX
Data types in c++
PPTX
Data types
PPTX
Recursive Function
PPTX
Structure in C
PPT
Introduction to c programming
PPTX
data types in C programming
PDF
Introduction to c++ ppt
PPTX
Arrays in c
PPTX
Control statements in c
PPTX
Array and string
PPTX
Dynamic memory allocation in c
PPTX
Variables in python
PPT
Operators in C Programming
PPTX
C tokens
PPTX
Keywords in c language
PPTX
User defined functions in C
PPT
Operator Overloading
PPTX
C language ppt
Data types in C
Data types in c++
Data types
Recursive Function
Structure in C
Introduction to c programming
data types in C programming
Introduction to c++ ppt
Arrays in c
Control statements in c
Array and string
Dynamic memory allocation in c
Variables in python
Operators in C Programming
C tokens
Keywords in c language
User defined functions in C
Operator Overloading
C language ppt
Ad

Viewers also liked (6)

PPT
Comments in C Programming
PPT
Chapter1 c programming data types, variables and constants
PPT
C ppt
PPSX
INTRODUCTION TO C PROGRAMMING
PPT
Basics of C programming
PPTX
Storage class in C Language
Comments in C Programming
Chapter1 c programming data types, variables and constants
C ppt
INTRODUCTION TO C PROGRAMMING
Basics of C programming
Storage class in C Language
Ad

Similar to Constants in C Programming (20)

PPT
Constants
PPTX
Introduction to C language programming.pptx
PPTX
Constants, Variables, and Data Types
PDF
Lecture 1 introduction of C Programming Language
PPTX
Constants in C
PPTX
COM1407: Variables and Data Types
PPT
C PROGRAMMING LANGUAGE CHARACTER SET UNIT 2.ppt
PPTX
Data Types and Variables In C Programming
PPTX
Constant, variables, data types
PPTX
Data types
PPTX
Data types
PPTX
FUNDAMENTAL OF C
PDF
Constants Variables Datatypes by Mrs. Sowmya Jyothi
PDF
[ITP - Lecture 04] Variables and Constants in C/C++
PPTX
C Programming Lecture 3 - Elements of C.pptx
PPSX
Programming in c
PDF
Basic of the C language
PPT
Mesics lecture 3 c – constants and variables
PPTX
ASSIGNMENT_1[1][1][1][1][1] (1) variables.pptx
PPSX
CS106 Lab 2 - Variables declaration
Constants
Introduction to C language programming.pptx
Constants, Variables, and Data Types
Lecture 1 introduction of C Programming Language
Constants in C
COM1407: Variables and Data Types
C PROGRAMMING LANGUAGE CHARACTER SET UNIT 2.ppt
Data Types and Variables In C Programming
Constant, variables, data types
Data types
Data types
FUNDAMENTAL OF C
Constants Variables Datatypes by Mrs. Sowmya Jyothi
[ITP - Lecture 04] Variables and Constants in C/C++
C Programming Lecture 3 - Elements of C.pptx
Programming in c
Basic of the C language
Mesics lecture 3 c – constants and variables
ASSIGNMENT_1[1][1][1][1][1] (1) variables.pptx
CS106 Lab 2 - Variables declaration

Recently uploaded (20)

PDF
Anesthesia in Laparoscopic Surgery in India
PDF
RMMM.pdf make it easy to upload and study
PDF
O5-L3 Freight Transport Ops (International) V1.pdf
PDF
Chapter 2 Heredity, Prenatal Development, and Birth.pdf
PDF
TR - Agricultural Crops Production NC III.pdf
PDF
Classroom Observation Tools for Teachers
PDF
Microbial disease of the cardiovascular and lymphatic systems
PDF
Module 4: Burden of Disease Tutorial Slides S2 2025
PPTX
Renaissance Architecture: A Journey from Faith to Humanism
PPTX
BOWEL ELIMINATION FACTORS AFFECTING AND TYPES
PPTX
PPH.pptx obstetrics and gynecology in nursing
PPTX
Pharma ospi slides which help in ospi learning
PDF
Basic Mud Logging Guide for educational purpose
PPTX
Cell Structure & Organelles in detailed.
PDF
2.FourierTransform-ShortQuestionswithAnswers.pdf
PDF
Physiotherapy_for_Respiratory_and_Cardiac_Problems WEBBER.pdf
PPTX
The Healthy Child – Unit II | Child Health Nursing I | B.Sc Nursing 5th Semester
PDF
Origin of periodic table-Mendeleev’s Periodic-Modern Periodic table
PDF
Business Ethics Teaching Materials for college
PDF
The Lost Whites of Pakistan by Jahanzaib Mughal.pdf
Anesthesia in Laparoscopic Surgery in India
RMMM.pdf make it easy to upload and study
O5-L3 Freight Transport Ops (International) V1.pdf
Chapter 2 Heredity, Prenatal Development, and Birth.pdf
TR - Agricultural Crops Production NC III.pdf
Classroom Observation Tools for Teachers
Microbial disease of the cardiovascular and lymphatic systems
Module 4: Burden of Disease Tutorial Slides S2 2025
Renaissance Architecture: A Journey from Faith to Humanism
BOWEL ELIMINATION FACTORS AFFECTING AND TYPES
PPH.pptx obstetrics and gynecology in nursing
Pharma ospi slides which help in ospi learning
Basic Mud Logging Guide for educational purpose
Cell Structure & Organelles in detailed.
2.FourierTransform-ShortQuestionswithAnswers.pdf
Physiotherapy_for_Respiratory_and_Cardiac_Problems WEBBER.pdf
The Healthy Child – Unit II | Child Health Nursing I | B.Sc Nursing 5th Semester
Origin of periodic table-Mendeleev’s Periodic-Modern Periodic table
Business Ethics Teaching Materials for college
The Lost Whites of Pakistan by Jahanzaib Mughal.pdf

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