SlideShare une entreprise Scribd logo
1  sur  13
Constant ,Variables & Data Types
Constant:-
• Constant is C refer to fixed value that do not change during the
execution of a program. C supports several types of constant.
1) Integer constants
2) Real constants
3) Single character constant
4) String constant
Integer constant:-
• An integer constant refers to a sequence of digits. There are three types of integer
,namely ,decimal integer ,octal integer ,hexadecimal integer.
• Decimal integer consist of a set of digit, 0 through 9, preceded by an optional – or
+ sign. Examples:- 123,-321,0,654321,+78
• Embedded spaces, commas, and non-digit character are not permitted between
digits. For examples:-15750,20000,$1000
• A sequence of digits preceded by 0x or oX is considered as hexadecimal integer.
They may also include alphabets A through f. the letter A through F represent the
numbers 10 through 15. Examples:-0X2 ,0x9F ,0Xbcd ,0x
• We rarely use octal and hexadecimal numbers in programing.
• The largest integer value that can be stored in machine-dependent. It is 32767 on
16-bit machines and 2,147,483,647 on 32 bit- machines.
Real constants:-
• Integer number are inadequate quantities that vary continuously, such as distances,
heights, temperature, prices, and so on. These quantities are represented by
numbers containing fractional parts like 17.548. such numbers are called real
constants.
• These numbers are shown in decimal notation, having a whole number followed
by a decimal point and the fractional part.
• A real number may also be expressed in exponential notation. For example, the
value 215.65 may be written as 2.165e2 in exponential notation. e2 means
multiply by 10*10.
• The mantissa is either a real number expressed in decimal notation or an integer.
The exponent is an integer number with an optional plus or minus sign. The letter
e separating the mantissa and the exponent can be written in either lowercase or
uppercase. Since the exponent causes the decimal point to “float”, this notation is
said to represent a real number in floating point form.
Example:-0.65e4, 12e-2 1.5e+5
Single Character Constant:-
• A single character constant contains a single character enclosed within a pair of
single quote marks. Example:- ‘5’, ‘X’
• Character constant have integer values known as ASCII value.
Example:- printf(“%d”, ‘a’)
Would print the number 97, the ASCII value of the letter a. the statement
• Since each character constant represents an integer value, it is also possible to
perform arithmetic operations on character.
String constant:-
• A string constant is a sequence of characters enclosed in double
quotes. The characters may be letters, numbers, special characters and
blank space. Example:-”Hello!”, “WEL DONE”
• Remember that a character constant is not equivalent to the single
character string constant. Further, a single character string constant
does not have an equivalent integer value while a character constant
has an integer value. Character strings are often used in programs to
build meaningful programs.
Variables:-
• A variable is a data name that be used to store a data value. Unlike constant
that remain unchanged during the execution of a program, a variable may
take different values at different times during execution.
• A variable name can be chosen by the programmer in a meaningful way so
as to reflect its function or nature in the program.
Examples:- Average, height, Total
• As mentioned earlier, variable names consist of letter, digits, and the
underscore(_) character, subject to the following conditions:
1) They must begin with a letter. Some systems permit inderscore as the first
character.
2) Uppercase and lowercase are significant. That is, variable Total is not the
same as total or TOTAL.
3) It should not be a keyword.
4) White space is not allowed.
Data Types:-
• C language is rich in its data types. Storage representations and
machine instructions to handle constants differ from machine to
machine. the variety of data types available allow the programmer to
select the type appropriate to the need of the applications as well as the
machine.
• ANSI C support three classes of data types:
1) Primary data type
2) Derived data types
3) User-defined data type
All C compilers support five fundamental data types, namely
integer(int), character(char), floating point(float), double-precision
floating point(double),and void.
Integer types:-
• Integers are whole numbers with a range of values supported by a
particular machine. Generally occupy one word of storage, and since
the word sizes of machines vary the size of an integer that can be
stored depends on the computer. If we use a 16 bit word length, the
size of the integer value is limited to the range -32768 to +32767.
• In order to provide some control over the range of numbers and
storage space, C has three classes of integer storage, namely short int,
int and long int, in both signed and unsigned forms. ANSI C defines
these types so that they can be organized from the smallest to the
largest.
• Short int
int
Long int
Floating Point Types:-
• Floating point numbers are stored in 32 bits, with 6digits of precision.
Floating point numbers are defined in C by the keyword float. When
the accuracy provided by a float number is not sufficient, the type
double can be used to define the number.
• A double data type number user 64 bits giving a precision of 14 digits.
These are known as double precision numbers. Remember that double
type represents the same data type that float represents, but with a
greater precision. To extend the precision further, we may use long
double which uses 80 bits.
Float
double
Long double
Void Types:-
• The void types has no values. This is usually used to specify the type
of functions. The type of a function is said to be void when it does not
return any value to the calling function. It can also play the role of a
generic type, meaning that it can represent any of the other standard
types.
Character types:-
• A single character can be defined as a character(char) type data.
Characters are usually stoped in 8 bits of internal storage. The qualifier
signed or unsigned may be explicitly applied to char. While unsigned
char have between 0 and 255, signed chars have values from -128 to
127.
Constant, variables, data types

Contenu connexe

Tendances

Tendances (20)

Algorithm
AlgorithmAlgorithm
Algorithm
 
Operators and expressions in c language
Operators and expressions in c languageOperators and expressions in c language
Operators and expressions in c language
 
C tokens
C tokensC tokens
C tokens
 
Data types
Data typesData types
Data types
 
Character set of c
Character set of cCharacter set of c
Character set of c
 
INTRODUCTION TO C PROGRAMMING
INTRODUCTION TO C PROGRAMMINGINTRODUCTION TO C PROGRAMMING
INTRODUCTION TO C PROGRAMMING
 
What is identifier c programming
What is identifier c programmingWhat is identifier c programming
What is identifier c programming
 
Pointers in c++
Pointers in c++Pointers in c++
Pointers in c++
 
Basics of pointer, pointer expressions, pointer to pointer and pointer in fun...
Basics of pointer, pointer expressions, pointer to pointer and pointer in fun...Basics of pointer, pointer expressions, pointer to pointer and pointer in fun...
Basics of pointer, pointer expressions, pointer to pointer and pointer in fun...
 
Break and continue
Break and continueBreak and continue
Break and continue
 
Basics of c++ Programming Language
Basics of c++ Programming LanguageBasics of c++ Programming Language
Basics 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
 
Structure in C
Structure in CStructure in C
Structure in C
 
Data types in C
Data types in CData types in C
Data types in C
 
Union in C programming
Union in C programmingUnion in C programming
Union in C programming
 
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
 
File handling in c
File handling in cFile handling in c
File handling in c
 
Array in c
Array in cArray in c
Array in c
 
Input output statement in C
Input output statement in CInput output statement in C
Input output statement in C
 
Strings in c
Strings in cStrings in c
Strings in c
 

En vedette (12)

Data types and Operators
Data types and OperatorsData types and Operators
Data types and Operators
 
Output in c++ (cout)
Output in c++ (cout)Output in c++ (cout)
Output in c++ (cout)
 
04 data types & variables
04   data types & variables04   data types & variables
04 data types & variables
 
Data types and variables
Data types and variablesData types and variables
Data types and variables
 
Data types ,variables,array
Data types ,variables,arrayData types ,variables,array
Data types ,variables,array
 
Sdd HSC Summary
Sdd HSC SummarySdd HSC Summary
Sdd HSC Summary
 
Software Design and Development
Software Design and DevelopmentSoftware Design and Development
Software Design and Development
 
IPT HSC Summary
IPT HSC SummaryIPT HSC Summary
IPT HSC Summary
 
Variables, Data Types, Operator & Expression in c in detail
Variables, Data Types, Operator & Expression in c in detailVariables, Data Types, Operator & Expression in c in detail
Variables, Data Types, Operator & Expression in c in detail
 
R Programming: Variables & Data Types
R Programming: Variables & Data TypesR Programming: Variables & Data Types
R Programming: Variables & Data Types
 
02. Data Type and Variables
02. Data Type and Variables02. Data Type and Variables
02. Data Type and Variables
 
Variables and Tables
Variables and TablesVariables and Tables
Variables and Tables
 

Similaire à Constant, variables, data types

CONSTANTS, VARIABLES & DATATYPES IN C
CONSTANTS, VARIABLES & DATATYPES IN CCONSTANTS, VARIABLES & DATATYPES IN C
CONSTANTS, VARIABLES & DATATYPES IN C
Sahithi Naraparaju
 
Structure of c_program_to_input_output
Structure of c_program_to_input_outputStructure of c_program_to_input_output
Structure of c_program_to_input_output
Anil Dutt
 
LESSON1-C_programming (1).GRADE 8 LESSONpptx
LESSON1-C_programming (1).GRADE 8 LESSONpptxLESSON1-C_programming (1).GRADE 8 LESSONpptx
LESSON1-C_programming (1).GRADE 8 LESSONpptx
joachimbenedicttulau
 

Similaire à Constant, variables, data types (20)

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
 
CONSTANTS, VARIABLES & DATATYPES IN C
CONSTANTS, VARIABLES & DATATYPES IN CCONSTANTS, VARIABLES & DATATYPES IN C
CONSTANTS, VARIABLES & DATATYPES IN C
 
Module 1:Introduction
Module 1:IntroductionModule 1:Introduction
Module 1:Introduction
 
Constants variables data_types
Constants variables data_typesConstants variables data_types
Constants variables data_types
 
Structure of c_program_to_input_output
Structure of c_program_to_input_outputStructure of c_program_to_input_output
Structure of c_program_to_input_output
 
All C ppt.ppt
All C ppt.pptAll C ppt.ppt
All C ppt.ppt
 
A Closer Look at Data Types, Variables and Expressions
A Closer Look at Data Types, Variables and ExpressionsA Closer Look at Data Types, Variables and Expressions
A Closer Look at Data Types, Variables and Expressions
 
C tokens.pptx
C tokens.pptxC tokens.pptx
C tokens.pptx
 
5-Lec - Datatypes.ppt
5-Lec - Datatypes.ppt5-Lec - Datatypes.ppt
5-Lec - Datatypes.ppt
 
Lecture 2
Lecture 2Lecture 2
Lecture 2
 
Unit 1 Built in Data types in C language.ppt
Unit 1 Built in Data types in C language.pptUnit 1 Built in Data types in C language.ppt
Unit 1 Built in Data types in C language.ppt
 
Programming in c
Programming in cProgramming in c
Programming in c
 
C programming tutorial
C programming tutorialC programming tutorial
C programming tutorial
 
C presentation book
C presentation bookC presentation book
C presentation book
 
LESSON1-C_programming (1).GRADE 8 LESSONpptx
LESSON1-C_programming (1).GRADE 8 LESSONpptxLESSON1-C_programming (1).GRADE 8 LESSONpptx
LESSON1-C_programming (1).GRADE 8 LESSONpptx
 
COM1407: Variables and Data Types
COM1407: Variables and Data Types COM1407: Variables and Data Types
COM1407: Variables and Data Types
 
Bsc cs i pic u-2 datatypes and variables in c language
Bsc cs i pic u-2 datatypes and variables in c languageBsc cs i pic u-2 datatypes and variables in c language
Bsc cs i pic u-2 datatypes and variables in c language
 
Diploma ii cfpc u-2 datatypes and variables in c language
Diploma ii  cfpc u-2 datatypes and variables in c languageDiploma ii  cfpc u-2 datatypes and variables in c language
Diploma ii cfpc u-2 datatypes and variables in c language
 
Mca i pic u-2 datatypes and variables in c language
Mca i pic u-2 datatypes and variables in c languageMca i pic u-2 datatypes and variables in c language
Mca i pic u-2 datatypes and variables in c language
 
Unit 2. Elements of C
Unit 2. Elements of CUnit 2. Elements of C
Unit 2. Elements of C
 

Dernier

Vishram Singh - Textbook of Anatomy Upper Limb and Thorax.. Volume 1 (1).pdf
Vishram Singh - Textbook of Anatomy  Upper Limb and Thorax.. Volume 1 (1).pdfVishram Singh - Textbook of Anatomy  Upper Limb and Thorax.. Volume 1 (1).pdf
Vishram Singh - Textbook of Anatomy Upper Limb and Thorax.. Volume 1 (1).pdf
ssuserdda66b
 
Activity 01 - Artificial Culture (1).pdf
Activity 01 - Artificial Culture (1).pdfActivity 01 - Artificial Culture (1).pdf
Activity 01 - Artificial Culture (1).pdf
ciinovamais
 
The basics of sentences session 3pptx.pptx
The basics of sentences session 3pptx.pptxThe basics of sentences session 3pptx.pptx
The basics of sentences session 3pptx.pptx
heathfieldcps1
 
1029 - Danh muc Sach Giao Khoa 10 . pdf
1029 -  Danh muc Sach Giao Khoa 10 . pdf1029 -  Danh muc Sach Giao Khoa 10 . pdf
1029 - Danh muc Sach Giao Khoa 10 . pdf
QucHHunhnh
 

Dernier (20)

Vishram Singh - Textbook of Anatomy Upper Limb and Thorax.. Volume 1 (1).pdf
Vishram Singh - Textbook of Anatomy  Upper Limb and Thorax.. Volume 1 (1).pdfVishram Singh - Textbook of Anatomy  Upper Limb and Thorax.. Volume 1 (1).pdf
Vishram Singh - Textbook of Anatomy Upper Limb and Thorax.. Volume 1 (1).pdf
 
How to Manage Global Discount in Odoo 17 POS
How to Manage Global Discount in Odoo 17 POSHow to Manage Global Discount in Odoo 17 POS
How to Manage Global Discount in Odoo 17 POS
 
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...
 
Food safety_Challenges food safety laboratories_.pdf
Food safety_Challenges food safety laboratories_.pdfFood safety_Challenges food safety laboratories_.pdf
Food safety_Challenges food safety laboratories_.pdf
 
SKILL OF INTRODUCING THE LESSON MICRO SKILLS.pptx
SKILL OF INTRODUCING THE LESSON MICRO SKILLS.pptxSKILL OF INTRODUCING THE LESSON MICRO SKILLS.pptx
SKILL OF INTRODUCING THE LESSON MICRO SKILLS.pptx
 
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.
 
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
 
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
 
Understanding Accommodations and Modifications
Understanding  Accommodations and ModificationsUnderstanding  Accommodations and Modifications
Understanding Accommodations and Modifications
 
Activity 01 - Artificial Culture (1).pdf
Activity 01 - Artificial Culture (1).pdfActivity 01 - Artificial Culture (1).pdf
Activity 01 - Artificial Culture (1).pdf
 
Towards a code of practice for AI in AT.pptx
Towards a code of practice for AI in AT.pptxTowards a code of practice for AI in AT.pptx
Towards a code of practice for AI in AT.pptx
 
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Ữ Â...
 
Single or Multiple melodic lines structure
Single or Multiple melodic lines structureSingle or Multiple melodic lines structure
Single or Multiple melodic lines structure
 
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...
 
The basics of sentences session 3pptx.pptx
The basics of sentences session 3pptx.pptxThe basics of sentences session 3pptx.pptx
The basics of sentences session 3pptx.pptx
 
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
 
1029 - Danh muc Sach Giao Khoa 10 . pdf
1029 -  Danh muc Sach Giao Khoa 10 . pdf1029 -  Danh muc Sach Giao Khoa 10 . pdf
1029 - Danh muc Sach Giao Khoa 10 . pdf
 
Micro-Scholarship, What it is, How can it help me.pdf
Micro-Scholarship, What it is, How can it help me.pdfMicro-Scholarship, What it is, How can it help me.pdf
Micro-Scholarship, What it is, How can it help me.pdf
 
ICT role in 21st century education and it's challenges.
ICT role in 21st century education and it's challenges.ICT role in 21st century education and it's challenges.
ICT role in 21st century education and it's challenges.
 
Unit-IV- Pharma. Marketing Channels.pptx
Unit-IV- Pharma. Marketing Channels.pptxUnit-IV- Pharma. Marketing Channels.pptx
Unit-IV- Pharma. Marketing Channels.pptx
 

Constant, variables, data types

  • 2. Constant:- • Constant is C refer to fixed value that do not change during the execution of a program. C supports several types of constant. 1) Integer constants 2) Real constants 3) Single character constant 4) String constant
  • 3. Integer constant:- • An integer constant refers to a sequence of digits. There are three types of integer ,namely ,decimal integer ,octal integer ,hexadecimal integer. • Decimal integer consist of a set of digit, 0 through 9, preceded by an optional – or + sign. Examples:- 123,-321,0,654321,+78 • Embedded spaces, commas, and non-digit character are not permitted between digits. For examples:-15750,20000,$1000 • A sequence of digits preceded by 0x or oX is considered as hexadecimal integer. They may also include alphabets A through f. the letter A through F represent the numbers 10 through 15. Examples:-0X2 ,0x9F ,0Xbcd ,0x • We rarely use octal and hexadecimal numbers in programing. • The largest integer value that can be stored in machine-dependent. It is 32767 on 16-bit machines and 2,147,483,647 on 32 bit- machines.
  • 4. Real constants:- • Integer number are inadequate quantities that vary continuously, such as distances, heights, temperature, prices, and so on. These quantities are represented by numbers containing fractional parts like 17.548. such numbers are called real constants. • These numbers are shown in decimal notation, having a whole number followed by a decimal point and the fractional part. • A real number may also be expressed in exponential notation. For example, the value 215.65 may be written as 2.165e2 in exponential notation. e2 means multiply by 10*10. • The mantissa is either a real number expressed in decimal notation or an integer. The exponent is an integer number with an optional plus or minus sign. The letter e separating the mantissa and the exponent can be written in either lowercase or uppercase. Since the exponent causes the decimal point to “float”, this notation is said to represent a real number in floating point form. Example:-0.65e4, 12e-2 1.5e+5
  • 5. Single Character Constant:- • A single character constant contains a single character enclosed within a pair of single quote marks. Example:- ‘5’, ‘X’ • Character constant have integer values known as ASCII value. Example:- printf(“%d”, ‘a’) Would print the number 97, the ASCII value of the letter a. the statement • Since each character constant represents an integer value, it is also possible to perform arithmetic operations on character.
  • 6. String constant:- • A string constant is a sequence of characters enclosed in double quotes. The characters may be letters, numbers, special characters and blank space. Example:-”Hello!”, “WEL DONE” • Remember that a character constant is not equivalent to the single character string constant. Further, a single character string constant does not have an equivalent integer value while a character constant has an integer value. Character strings are often used in programs to build meaningful programs.
  • 7. Variables:- • A variable is a data name that be used to store a data value. Unlike constant that remain unchanged during the execution of a program, a variable may take different values at different times during execution. • A variable name can be chosen by the programmer in a meaningful way so as to reflect its function or nature in the program. Examples:- Average, height, Total • As mentioned earlier, variable names consist of letter, digits, and the underscore(_) character, subject to the following conditions: 1) They must begin with a letter. Some systems permit inderscore as the first character. 2) Uppercase and lowercase are significant. That is, variable Total is not the same as total or TOTAL. 3) It should not be a keyword. 4) White space is not allowed.
  • 8. Data Types:- • C language is rich in its data types. Storage representations and machine instructions to handle constants differ from machine to machine. the variety of data types available allow the programmer to select the type appropriate to the need of the applications as well as the machine. • ANSI C support three classes of data types: 1) Primary data type 2) Derived data types 3) User-defined data type All C compilers support five fundamental data types, namely integer(int), character(char), floating point(float), double-precision floating point(double),and void.
  • 9. Integer types:- • Integers are whole numbers with a range of values supported by a particular machine. Generally occupy one word of storage, and since the word sizes of machines vary the size of an integer that can be stored depends on the computer. If we use a 16 bit word length, the size of the integer value is limited to the range -32768 to +32767. • In order to provide some control over the range of numbers and storage space, C has three classes of integer storage, namely short int, int and long int, in both signed and unsigned forms. ANSI C defines these types so that they can be organized from the smallest to the largest. • Short int int Long int
  • 10. Floating Point Types:- • Floating point numbers are stored in 32 bits, with 6digits of precision. Floating point numbers are defined in C by the keyword float. When the accuracy provided by a float number is not sufficient, the type double can be used to define the number. • A double data type number user 64 bits giving a precision of 14 digits. These are known as double precision numbers. Remember that double type represents the same data type that float represents, but with a greater precision. To extend the precision further, we may use long double which uses 80 bits. Float double Long double
  • 11. Void Types:- • The void types has no values. This is usually used to specify the type of functions. The type of a function is said to be void when it does not return any value to the calling function. It can also play the role of a generic type, meaning that it can represent any of the other standard types.
  • 12. Character types:- • A single character can be defined as a character(char) type data. Characters are usually stoped in 8 bits of internal storage. The qualifier signed or unsigned may be explicitly applied to char. While unsigned char have between 0 and 255, signed chars have values from -128 to 127.