SlideShare une entreprise Scribd logo
1  sur  20
C – Constants and Variables

       www.eshikshak.co.in
C - Constants

                Constants



    Primary                           Secondary
   Constants                          Constants


Integer Constants                       Array
 Real Constants                         Pointer
    Character                          Structure
    Constants                           Union
                                       Enum. etc

                www.eshikshak.co.in
Rules for Constructing Integer Constants
   An integer constant must have at least one digit.
   It must not have a decimal point.
      1, 2, -3, 99, 1000 are valid integer constant
      1.3, 2.00, 0.01, -99, 100.9 are invalid integer constant
   It can be either positive or negative.
   If no sign precedes an integer constant it is assumed to be
    positive.
   No commas or blanks are allowed within an integer constant.
   The allowable range for integer constants is -32768 to 32767.
   Ex.: 426
       +782
       -8000
       -7605




                          www.eshikshak.co.in
Rules for Constructing Real Constants
  A real constant must have at least one digit.
  It must have a decimal point.
  It could be either positive or negative.
  Default sign is positive.
  No commas or blanks are allowed within a
   real constant.
 • Ex.: +325.34
         426.0
          -32.76
          -48.5792
Rules for Constructing Character Constants


 • A characterspecial symbolsingle alphabet, asingle digit
   or a single
               constant is a
                             enclosed within
                                               single

   inverted commas.
 • Both the inverted commas should point to the left. For
   example, ’A’ is a valid character constant whereas ‘A’
   is not.
 • The maximum length of a character constant can be 1
   character.
 Ex.: 'A'
      'I'
      '5'
      '='
Variable
 Variables in C have the same meaning as variables in
  algebra. That is, they represent some unknown, or
  variable, value.


   •x=a+b
   • z + 2 = 3(y - 5)
 Remember that variables in algebra are represented by a
  single alphabetic character




                      www.eshikshak.co.in
Variable
 A variable is a used to store values. It has memory
  location and can store single value at a time.
 A variable is a data name used for storing a data
  value. Its value may be changed during the
  program execution.
 The variable value keeps on changing during the
  execution of the program.




                    www.eshikshak.co.in
Naming Variables
• Variables in C may be given representations
  containing multiple characters. But there are
  rules for these representations.
• Variable names (identifiers) in C
  o May only consist of letters, digits, and
    underscores
  o May be as long as you like, but only the first 31
    characters are significant
  o May not begin with a digit
  o May not be a C reserved word (keyword)
Naming Conventions
 C programmers generally agree on the
  following conventions for naming variables.
 o   Begin variable names with lowercase letters
 o
   Use   meaningful            identifiers
 o Separate “words” within identifiers with
   underscores or mixed upper and lower case.
 o Examples: surfaceArea surface_Area
   surface_area
 o Be consistent!
Rules for Defining Variables
•   A variable must begin with a character or an underscore without spaces.
    The underscore is treated as one type of characters.
     – It is advised that the variable names should not start with underscore because
       library routines mostly use such variable names.
•   The length of the variable varies from compiler to compiler. Generally,
    most of the compilers support eight characters excluding extension.
     – ANSI standard recognizes the maximum length of a variable up to 31
       characters.
•   The variable should not be a C keyword.
•   The variable names may be a combination of uppercase and lowercase
    characters.
•   The variable name should not start with a digit.
•   Blanks and commas are not permitted within a variable name.

                                   www.eshikshak.co.in
C Data Types
                             C Data Types


Derived Data Type         Basic Data Type              User Defined Data Type


           Pointers                                     Pointers
           Functions                                    Functions
           Arrays                                       Arrays




               Integer                Floating Point                  void


            char                   float
            int                    double

                              www.eshikshak.co.in
C Data Types
Data Type       Size(bytes)                  Range            Format String
char                1                     -128 to 127              %c
unsigned char       1                       0 to 255               %c
short or int        2                  -32768 to 32767          %i or %d
unsigned int        2                     0 to 65535               %u
long                4          -2147483648 to 2147483647          %ld
unsigned long       4                 0 to 4294967295             %lu
float               4               3.4 e-38 to 3.4 e+38        %f or %g
double              8              1.7 e-308 to 1.7 e+308          %lf
long double         10           3.4 e-4932 to 1.1 e + 4932        %lf
enum                2*                 -32768 to 32767             %d




                              www.eshikshak.co.in
C Data types
 • Integer Data Type
       – int, short and long
       – All C compilers offers different integer data types.
Short Integer                                  Long Intger
Occupies 2 bytes in memory                     Occupies 4 bytes in memory
Range : -32768 to 32767                        Range : -2147483648 to 2147483647
Program runs faster                            Program runs slower
Format Specifier : %d or %i                    Format Specifier : %ld
Example :                                      Example :
int a = 2;                                     long b = 123456
short int b = 2;                               long int c=1234567
Note : when variable is declared without short or long keyword, the default is short-
signed int.
                                     www.eshikshak.co.in
C Data Types
 Difference between signed and unsigned integers
Signed Integer                         Unsigned Integer
Occupies 2 bytes in memory                     Occupies 4 bytes in memory
Range : -32768 to 32767                        Range : 0 to 65535
Format Specifier : %d or %i                    Format Specifier : %u
By default signed int is short signed int      By default unsigned int is short unsigned
                                               int
There are also long signed integers having     There are also long unsigned int with
range from -2147483648 to 2147483647           range 0 to 4294967295
Example :                                      Example:
int a=2;                                       unsigned long b=567898;
long int b=2;                                  unsigned short int c=223;
                                                When a variable is declared as unsigned
                                                the negative range of the data type is
                                                transferred to positive, i.e. doubles the
                                                largest size of possible value. This is due to
                                                delcaring unsigned int, the 16th bit is free
                                                and not used to store the sign of the
                                       www.eshikshak.co.in
                                                number
C Data Types
Signed Character                          Unsigned Character
Occupies 1 bytes in memory                Occupies 1 bytes in memory
Range : -128 to 127                       Range : 0 to 255
Format Specifier : %c                     Format Specifier : %c
When printed using %d format specifier    When printed using %d format specifier,
prints ASCII character                    pirnts ASCII character
char ch=‘b’                               unsigned char = ‘b’;




                                  www.eshikshak.co.in
C Data Type
Floating                                Double Floating
Occupies 4 bytes in memory              Occupies 8 bytes in memory
Range : 3.4e-38 to +3.4e+38             Range : 1.7 e-308 to +1.73+308;
Format String : %f                      Format String : %lf
Example :                               Example :
float a;                                double y;
                                        There also exist long double
                                        having ranged 3.4 e-4932 to 1.1e +
                                        4932 and occupies 10 bytes in
                                        memory

                                        Example :

                                        long double k;


                              www.eshikshak.co.in
Initialization Variables
•  Variable declared can be assigned operator ῾=᾽. The declaration and
   initialization can also be done in the same line.
Syntax :
   variable_name = constant;
  or
  data_type variable_name = constant;
Example :
   x = 5; where is an integer variable.
Example :
   int y = 4;
Example :
   int x,y,z;

                               www.eshikshak.co.in
Dynamic Initialization
•   The initialization of variable at run time is called dynamic initialization.
    Dynamic refers to the process during execution.
•   In C initialization can be done at any place in the program, however the
    declaration should be done at the declaration part only.
•   Example :
     void main()
     {
         int r=2;
         float area=3.14*r*r;
         clrscr();
          printf(“Area = %g”, area);
     }
     OUTPUT:
     Area=12.56;
                                       www.eshikshak.co.in
Example :

Type Modifiers                   void main()
                                 {
                                    short t = 1;
• The keywords signed,              long k = 54111;
                                     unsigned u = 10;
  unsigned, short and
                                     signed j = -10;
  long are type modifiers.
                                     clrscr();
• A     type     modifier             printf(“n t=%d”,t)
  changes the meaning of              printf(“n k=%ld”, k);
  basic data type and                 printf(“n u=%u, u);
                                      printf(“n j=%d”, j);
  produces a new type.
                                 }
• Each of these type                OUTPUT
  modifiers is applicable           t = 1;
                                     k = 54111;
  to the basic data type
                                     u = 10;
  int.                               j = -10
                       www.eshikshak.co.in
• Type Conversion
• Wrapping Around
• Constant and Volatile
  Variables



             www.eshikshak.co.in

Contenu connexe

Tendances

Lecture 2 variables
Lecture 2 variablesLecture 2 variables
Lecture 2 variables
Tony Apreku
 
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
 
Programming Fundamentals
Programming FundamentalsProgramming Fundamentals
Programming Fundamentals
Hassan293
 

Tendances (20)

Lecture02(constants, variable & data types)
Lecture02(constants, variable & data types)Lecture02(constants, variable & data types)
Lecture02(constants, variable & data types)
 
C Tokens
C TokensC Tokens
C Tokens
 
Variables and data types in C++
Variables and data types in C++Variables and data types in C++
Variables and data types in C++
 
Variables in C and C++ Language
Variables in C and C++ LanguageVariables in C and C++ Language
Variables in C and C++ Language
 
Complete Tokens in c/c++
Complete Tokens in c/c++Complete Tokens in c/c++
Complete Tokens in c/c++
 
Datatype in c++ unit 3 -topic 2
Datatype in c++ unit 3 -topic 2Datatype in c++ unit 3 -topic 2
Datatype in c++ unit 3 -topic 2
 
Tokens in C++
Tokens in C++Tokens in C++
Tokens 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
 
Lecture 2 variables
Lecture 2 variablesLecture 2 variables
Lecture 2 variables
 
Numeric Data Types & Strings
Numeric Data Types & StringsNumeric Data Types & Strings
Numeric Data Types & Strings
 
constants, variables and datatypes in C
constants, variables and datatypes in Cconstants, variables and datatypes in C
constants, variables and datatypes in C
 
Data type in c
Data type in cData type in c
Data type in c
 
What is identifier c programming
What is identifier c programmingWhat is identifier c programming
What is identifier c programming
 
C data type format specifier
C data type format specifierC data type format specifier
C data type format specifier
 
Programming Fundamentals
Programming FundamentalsProgramming Fundamentals
Programming Fundamentals
 
Data types
Data typesData types
Data types
 
Data types in java | What is Datatypes in Java | Learning with RD | Created b...
Data types in java | What is Datatypes in Java | Learning with RD | Created b...Data types in java | What is Datatypes in Java | Learning with RD | Created b...
Data types in java | What is Datatypes in Java | Learning with RD | Created b...
 
2 expressions (ppt-2) in C++
2 expressions (ppt-2) in C++2 expressions (ppt-2) in C++
2 expressions (ppt-2) in C++
 
Java: Primitive Data Types
Java: Primitive Data TypesJava: Primitive Data Types
Java: Primitive Data Types
 
Constants variables data_types
Constants variables data_typesConstants variables data_types
Constants variables data_types
 

En vedette

Lecture7relationalandlogicaloperators 110823181038-phpapp02
Lecture7relationalandlogicaloperators 110823181038-phpapp02Lecture7relationalandlogicaloperators 110823181038-phpapp02
Lecture7relationalandlogicaloperators 110823181038-phpapp02
eShikshak
 
Algorithm chapter 11
Algorithm chapter 11Algorithm chapter 11
Algorithm chapter 11
chidabdu
 
Lecture19 unionsin c.ppt
Lecture19 unionsin c.pptLecture19 unionsin c.ppt
Lecture19 unionsin c.ppt
eShikshak
 
Html text and formatting
Html text and formattingHtml text and formatting
Html text and formatting
eShikshak
 
Mesics lecture 4 c operators and experssions
Mesics lecture  4   c operators and experssionsMesics lecture  4   c operators and experssions
Mesics lecture 4 c operators and experssions
eShikshak
 

En vedette (20)

C programming
C programmingC programming
C programming
 
Html phrase tags
Html phrase tagsHtml phrase tags
Html phrase tags
 
Mesics lecture 5 input – output in ‘c’
Mesics lecture 5   input – output in ‘c’Mesics lecture 5   input – output in ‘c’
Mesics lecture 5 input – output in ‘c’
 
Lecture21 categoriesof userdefinedfunctions.ppt
Lecture21 categoriesof userdefinedfunctions.pptLecture21 categoriesof userdefinedfunctions.ppt
Lecture21 categoriesof userdefinedfunctions.ppt
 
Lecture15 comparisonoftheloopcontrolstructures.ppt
Lecture15 comparisonoftheloopcontrolstructures.pptLecture15 comparisonoftheloopcontrolstructures.ppt
Lecture15 comparisonoftheloopcontrolstructures.ppt
 
Lecture 7 relational_and_logical_operators
Lecture 7 relational_and_logical_operatorsLecture 7 relational_and_logical_operators
Lecture 7 relational_and_logical_operators
 
Lecture7relationalandlogicaloperators 110823181038-phpapp02
Lecture7relationalandlogicaloperators 110823181038-phpapp02Lecture7relationalandlogicaloperators 110823181038-phpapp02
Lecture7relationalandlogicaloperators 110823181038-phpapp02
 
Mesics lecture files in 'c'
Mesics lecture   files in 'c'Mesics lecture   files in 'c'
Mesics lecture files in 'c'
 
Algorithm
AlgorithmAlgorithm
Algorithm
 
Mesics lecture 7 iteration and repetitive executions
Mesics lecture 7   iteration and repetitive executionsMesics lecture 7   iteration and repetitive executions
Mesics lecture 7 iteration and repetitive executions
 
Mesics lecture 8 arrays in 'c'
Mesics lecture 8   arrays in 'c'Mesics lecture 8   arrays in 'c'
Mesics lecture 8 arrays in 'c'
 
Unit 1.3 types of cloud
Unit 1.3 types of cloudUnit 1.3 types of cloud
Unit 1.3 types of cloud
 
Unit 1.1 introduction to cloud computing
Unit 1.1   introduction to cloud computingUnit 1.1   introduction to cloud computing
Unit 1.1 introduction to cloud computing
 
Algorithm chapter 11
Algorithm chapter 11Algorithm chapter 11
Algorithm chapter 11
 
Unit 1.2 move to cloud computing
Unit 1.2   move to cloud computingUnit 1.2   move to cloud computing
Unit 1.2 move to cloud computing
 
Lecture19 unionsin c.ppt
Lecture19 unionsin c.pptLecture19 unionsin c.ppt
Lecture19 unionsin c.ppt
 
Html text and formatting
Html text and formattingHtml text and formatting
Html text and formatting
 
Linked list
Linked listLinked list
Linked list
 
Mesics lecture 4 c operators and experssions
Mesics lecture  4   c operators and experssionsMesics lecture  4   c operators and experssions
Mesics lecture 4 c operators and experssions
 
Lecture20 user definedfunctions.ppt
Lecture20 user definedfunctions.pptLecture20 user definedfunctions.ppt
Lecture20 user definedfunctions.ppt
 

Similaire à Mesics lecture 3 c – constants and variables

FP 201 Unit 2 - Part 2
FP 201 Unit 2 - Part 2FP 201 Unit 2 - Part 2
FP 201 Unit 2 - Part 2
rohassanie
 
Introduction of c_language
Introduction of c_languageIntroduction of c_language
Introduction of c_language
SINGH PROJECTS
 
CONSTANTS, VARIABLES & DATATYPES IN C
CONSTANTS, VARIABLES & DATATYPES IN CCONSTANTS, VARIABLES & DATATYPES IN C
CONSTANTS, VARIABLES & DATATYPES IN C
Sahithi Naraparaju
 
C the basic concepts
C the basic conceptsC the basic concepts
C the basic concepts
Abhinav Vatsa
 

Similaire à Mesics lecture 3 c – constants and variables (20)

FP 201 Unit 2 - Part 2
FP 201 Unit 2 - Part 2FP 201 Unit 2 - Part 2
FP 201 Unit 2 - Part 2
 
Datatypes
DatatypesDatatypes
Datatypes
 
Introduction to c++
Introduction to c++Introduction to c++
Introduction to c++
 
C language basics
C language basicsC language basics
C language basics
 
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
 
Data types slides by Faixan
Data types slides by FaixanData types slides by Faixan
Data types slides by Faixan
 
01 Java Language And OOP PART I
01 Java Language And OOP PART I01 Java Language And OOP PART I
01 Java Language And OOP PART I
 
Module 1:Introduction
Module 1:IntroductionModule 1:Introduction
Module 1:Introduction
 
Introduction of c_language
Introduction of c_languageIntroduction of c_language
Introduction of c_language
 
[ITP - Lecture 04] Variables and Constants in C/C++
[ITP - Lecture 04] Variables and Constants in C/C++[ITP - Lecture 04] Variables and Constants in C/C++
[ITP - Lecture 04] Variables and Constants in C/C++
 
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
 
PSPC--UNIT-2.pdf
PSPC--UNIT-2.pdfPSPC--UNIT-2.pdf
PSPC--UNIT-2.pdf
 
Data types
Data typesData types
Data types
 
C the basic concepts
C the basic conceptsC the basic concepts
C the basic concepts
 
Learn C LANGUAGE at ASIT
Learn C LANGUAGE at ASITLearn C LANGUAGE at ASIT
Learn C LANGUAGE at ASIT
 
C programming tutorial
C programming tutorialC programming tutorial
C programming tutorial
 
COM1407: Variables and Data Types
COM1407: Variables and Data Types COM1407: Variables and Data Types
COM1407: Variables and Data Types
 
Introduction
IntroductionIntroduction
Introduction
 
Chapter 2: Elementary Programming
Chapter 2: Elementary ProgrammingChapter 2: Elementary Programming
Chapter 2: Elementary Programming
 

Plus de eShikshak

Mesics lecture 5 input – output in ‘c’
Mesics lecture 5   input – output in ‘c’Mesics lecture 5   input – output in ‘c’
Mesics lecture 5 input – output in ‘c’
eShikshak
 
Lecturer23 pointersin c.ppt
Lecturer23 pointersin c.pptLecturer23 pointersin c.ppt
Lecturer23 pointersin c.ppt
eShikshak
 
Language processors
Language processorsLanguage processors
Language processors
eShikshak
 

Plus de eShikshak (16)

Modelling and evaluation
Modelling and evaluationModelling and evaluation
Modelling and evaluation
 
Operators in python
Operators in pythonOperators in python
Operators in python
 
Datatypes in python
Datatypes in pythonDatatypes in python
Datatypes in python
 
Introduction to python
Introduction to pythonIntroduction to python
Introduction to python
 
Introduction to e commerce
Introduction to e commerceIntroduction to e commerce
Introduction to e commerce
 
Chapeter 2 introduction to cloud computing
Chapeter 2   introduction to cloud computingChapeter 2   introduction to cloud computing
Chapeter 2 introduction to cloud computing
 
Unit 1.4 working of cloud computing
Unit 1.4 working of cloud computingUnit 1.4 working of cloud computing
Unit 1.4 working of cloud computing
 
Mesics lecture 6 control statement = if -else if__else
Mesics lecture 6   control statement = if -else if__elseMesics lecture 6   control statement = if -else if__else
Mesics lecture 6 control statement = if -else if__else
 
Mesics lecture 5 input – output in ‘c’
Mesics lecture 5   input – output in ‘c’Mesics lecture 5   input – output in ‘c’
Mesics lecture 5 input – output in ‘c’
 
Lecture18 structurein c.ppt
Lecture18 structurein c.pptLecture18 structurein c.ppt
Lecture18 structurein c.ppt
 
Lecture17 arrays.ppt
Lecture17 arrays.pptLecture17 arrays.ppt
Lecture17 arrays.ppt
 
Lecture13 control statementswitch.ppt
Lecture13 control statementswitch.pptLecture13 control statementswitch.ppt
Lecture13 control statementswitch.ppt
 
Lecturer23 pointersin c.ppt
Lecturer23 pointersin c.pptLecturer23 pointersin c.ppt
Lecturer23 pointersin c.ppt
 
Program development cyle
Program development cyleProgram development cyle
Program development cyle
 
Language processors
Language processorsLanguage processors
Language processors
 
Computer programming programming_langugages
Computer programming programming_langugagesComputer programming programming_langugages
Computer programming programming_langugages
 

Dernier

Dernier (20)

Boost PC performance: How more available memory can improve productivity
Boost PC performance: How more available memory can improve productivityBoost PC performance: How more available memory can improve productivity
Boost PC performance: How more available memory can improve productivity
 
Deploy with confidence: VMware Cloud Foundation 5.1 on next gen Dell PowerEdg...
Deploy with confidence: VMware Cloud Foundation 5.1 on next gen Dell PowerEdg...Deploy with confidence: VMware Cloud Foundation 5.1 on next gen Dell PowerEdg...
Deploy with confidence: VMware Cloud Foundation 5.1 on next gen Dell PowerEdg...
 
The 7 Things I Know About Cyber Security After 25 Years | April 2024
The 7 Things I Know About Cyber Security After 25 Years | April 2024The 7 Things I Know About Cyber Security After 25 Years | April 2024
The 7 Things I Know About Cyber Security After 25 Years | April 2024
 
2024: Domino Containers - The Next Step. News from the Domino Container commu...
2024: Domino Containers - The Next Step. News from the Domino Container commu...2024: Domino Containers - The Next Step. News from the Domino Container commu...
2024: Domino Containers - The Next Step. News from the Domino Container commu...
 
ProductAnonymous-April2024-WinProductDiscovery-MelissaKlemke
ProductAnonymous-April2024-WinProductDiscovery-MelissaKlemkeProductAnonymous-April2024-WinProductDiscovery-MelissaKlemke
ProductAnonymous-April2024-WinProductDiscovery-MelissaKlemke
 
Understanding Discord NSFW Servers A Guide for Responsible Users.pdf
Understanding Discord NSFW Servers A Guide for Responsible Users.pdfUnderstanding Discord NSFW Servers A Guide for Responsible Users.pdf
Understanding Discord NSFW Servers A Guide for Responsible Users.pdf
 
How to Troubleshoot Apps for the Modern Connected Worker
How to Troubleshoot Apps for the Modern Connected WorkerHow to Troubleshoot Apps for the Modern Connected Worker
How to Troubleshoot Apps for the Modern Connected Worker
 
presentation ICT roal in 21st century education
presentation ICT roal in 21st century educationpresentation ICT roal in 21st century education
presentation ICT roal in 21st century education
 
Strategies for Landing an Oracle DBA Job as a Fresher
Strategies for Landing an Oracle DBA Job as a FresherStrategies for Landing an Oracle DBA Job as a Fresher
Strategies for Landing an Oracle DBA Job as a Fresher
 
A Year of the Servo Reboot: Where Are We Now?
A Year of the Servo Reboot: Where Are We Now?A Year of the Servo Reboot: Where Are We Now?
A Year of the Servo Reboot: Where Are We Now?
 
Repurposing LNG terminals for Hydrogen Ammonia: Feasibility and Cost Saving
Repurposing LNG terminals for Hydrogen Ammonia: Feasibility and Cost SavingRepurposing LNG terminals for Hydrogen Ammonia: Feasibility and Cost Saving
Repurposing LNG terminals for Hydrogen Ammonia: Feasibility and Cost Saving
 
TrustArc Webinar - Stay Ahead of US State Data Privacy Law Developments
TrustArc Webinar - Stay Ahead of US State Data Privacy Law DevelopmentsTrustArc Webinar - Stay Ahead of US State Data Privacy Law Developments
TrustArc Webinar - Stay Ahead of US State Data Privacy Law Developments
 
Powerful Google developer tools for immediate impact! (2023-24 C)
Powerful Google developer tools for immediate impact! (2023-24 C)Powerful Google developer tools for immediate impact! (2023-24 C)
Powerful Google developer tools for immediate impact! (2023-24 C)
 
TrustArc Webinar - Unlock the Power of AI-Driven Data Discovery
TrustArc Webinar - Unlock the Power of AI-Driven Data DiscoveryTrustArc Webinar - Unlock the Power of AI-Driven Data Discovery
TrustArc Webinar - Unlock the Power of AI-Driven Data Discovery
 
Artificial Intelligence Chap.5 : Uncertainty
Artificial Intelligence Chap.5 : UncertaintyArtificial Intelligence Chap.5 : Uncertainty
Artificial Intelligence Chap.5 : Uncertainty
 
Manulife - Insurer Innovation Award 2024
Manulife - Insurer Innovation Award 2024Manulife - Insurer Innovation Award 2024
Manulife - Insurer Innovation Award 2024
 
Axa Assurance Maroc - Insurer Innovation Award 2024
Axa Assurance Maroc - Insurer Innovation Award 2024Axa Assurance Maroc - Insurer Innovation Award 2024
Axa Assurance Maroc - Insurer Innovation Award 2024
 
Partners Life - Insurer Innovation Award 2024
Partners Life - Insurer Innovation Award 2024Partners Life - Insurer Innovation Award 2024
Partners Life - Insurer Innovation Award 2024
 
Bajaj Allianz Life Insurance Company - Insurer Innovation Award 2024
Bajaj Allianz Life Insurance Company - Insurer Innovation Award 2024Bajaj Allianz Life Insurance Company - Insurer Innovation Award 2024
Bajaj Allianz Life Insurance Company - Insurer Innovation Award 2024
 
Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...
Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...
Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...
 

Mesics lecture 3 c – constants and variables

  • 1. C – Constants and Variables www.eshikshak.co.in
  • 2. C - Constants Constants Primary Secondary Constants Constants Integer Constants Array Real Constants Pointer Character Structure Constants Union Enum. etc www.eshikshak.co.in
  • 3. Rules for Constructing Integer Constants  An integer constant must have at least one digit.  It must not have a decimal point.  1, 2, -3, 99, 1000 are valid integer constant  1.3, 2.00, 0.01, -99, 100.9 are invalid integer constant  It can be either positive or negative.  If no sign precedes an integer constant it is assumed to be positive.  No commas or blanks are allowed within an integer constant.  The allowable range for integer constants is -32768 to 32767.  Ex.: 426 +782 -8000 -7605 www.eshikshak.co.in
  • 4. Rules for Constructing Real Constants  A real constant must have at least one digit.  It must have a decimal point.  It could be either positive or negative.  Default sign is positive.  No commas or blanks are allowed within a real constant. • Ex.: +325.34 426.0 -32.76 -48.5792
  • 5. Rules for Constructing Character Constants • A characterspecial symbolsingle alphabet, asingle digit or a single constant is a enclosed within single inverted commas. • Both the inverted commas should point to the left. For example, ’A’ is a valid character constant whereas ‘A’ is not. • The maximum length of a character constant can be 1 character. Ex.: 'A' 'I' '5' '='
  • 6. Variable  Variables in C have the same meaning as variables in algebra. That is, they represent some unknown, or variable, value. •x=a+b • z + 2 = 3(y - 5)  Remember that variables in algebra are represented by a single alphabetic character www.eshikshak.co.in
  • 7. Variable  A variable is a used to store values. It has memory location and can store single value at a time.  A variable is a data name used for storing a data value. Its value may be changed during the program execution.  The variable value keeps on changing during the execution of the program. www.eshikshak.co.in
  • 8. Naming Variables • Variables in C may be given representations containing multiple characters. But there are rules for these representations. • Variable names (identifiers) in C o May only consist of letters, digits, and underscores o May be as long as you like, but only the first 31 characters are significant o May not begin with a digit o May not be a C reserved word (keyword)
  • 9. Naming Conventions  C programmers generally agree on the following conventions for naming variables. o Begin variable names with lowercase letters o Use meaningful identifiers o Separate “words” within identifiers with underscores or mixed upper and lower case. o Examples: surfaceArea surface_Area surface_area o Be consistent!
  • 10. Rules for Defining Variables • A variable must begin with a character or an underscore without spaces. The underscore is treated as one type of characters. – It is advised that the variable names should not start with underscore because library routines mostly use such variable names. • The length of the variable varies from compiler to compiler. Generally, most of the compilers support eight characters excluding extension. – ANSI standard recognizes the maximum length of a variable up to 31 characters. • The variable should not be a C keyword. • The variable names may be a combination of uppercase and lowercase characters. • The variable name should not start with a digit. • Blanks and commas are not permitted within a variable name. www.eshikshak.co.in
  • 11. C Data Types C Data Types Derived Data Type Basic Data Type User Defined Data Type  Pointers  Pointers  Functions  Functions  Arrays  Arrays Integer Floating Point void  char  float  int  double www.eshikshak.co.in
  • 12. C Data Types Data Type Size(bytes) Range Format String char 1 -128 to 127 %c unsigned char 1 0 to 255 %c short or int 2 -32768 to 32767 %i or %d unsigned int 2 0 to 65535 %u long 4 -2147483648 to 2147483647 %ld unsigned long 4 0 to 4294967295 %lu float 4 3.4 e-38 to 3.4 e+38 %f or %g double 8 1.7 e-308 to 1.7 e+308 %lf long double 10 3.4 e-4932 to 1.1 e + 4932 %lf enum 2* -32768 to 32767 %d www.eshikshak.co.in
  • 13. C Data types • Integer Data Type – int, short and long – All C compilers offers different integer data types. Short Integer Long Intger Occupies 2 bytes in memory Occupies 4 bytes in memory Range : -32768 to 32767 Range : -2147483648 to 2147483647 Program runs faster Program runs slower Format Specifier : %d or %i Format Specifier : %ld Example : Example : int a = 2; long b = 123456 short int b = 2; long int c=1234567 Note : when variable is declared without short or long keyword, the default is short- signed int. www.eshikshak.co.in
  • 14. C Data Types Difference between signed and unsigned integers Signed Integer Unsigned Integer Occupies 2 bytes in memory Occupies 4 bytes in memory Range : -32768 to 32767 Range : 0 to 65535 Format Specifier : %d or %i Format Specifier : %u By default signed int is short signed int By default unsigned int is short unsigned int There are also long signed integers having There are also long unsigned int with range from -2147483648 to 2147483647 range 0 to 4294967295 Example : Example: int a=2; unsigned long b=567898; long int b=2; unsigned short int c=223; When a variable is declared as unsigned the negative range of the data type is transferred to positive, i.e. doubles the largest size of possible value. This is due to delcaring unsigned int, the 16th bit is free and not used to store the sign of the www.eshikshak.co.in number
  • 15. C Data Types Signed Character Unsigned Character Occupies 1 bytes in memory Occupies 1 bytes in memory Range : -128 to 127 Range : 0 to 255 Format Specifier : %c Format Specifier : %c When printed using %d format specifier When printed using %d format specifier, prints ASCII character pirnts ASCII character char ch=‘b’ unsigned char = ‘b’; www.eshikshak.co.in
  • 16. C Data Type Floating Double Floating Occupies 4 bytes in memory Occupies 8 bytes in memory Range : 3.4e-38 to +3.4e+38 Range : 1.7 e-308 to +1.73+308; Format String : %f Format String : %lf Example : Example : float a; double y; There also exist long double having ranged 3.4 e-4932 to 1.1e + 4932 and occupies 10 bytes in memory Example : long double k; www.eshikshak.co.in
  • 17. Initialization Variables • Variable declared can be assigned operator ῾=᾽. The declaration and initialization can also be done in the same line. Syntax : variable_name = constant; or data_type variable_name = constant; Example : x = 5; where is an integer variable. Example : int y = 4; Example : int x,y,z; www.eshikshak.co.in
  • 18. Dynamic Initialization • The initialization of variable at run time is called dynamic initialization. Dynamic refers to the process during execution. • In C initialization can be done at any place in the program, however the declaration should be done at the declaration part only. • Example : void main() { int r=2; float area=3.14*r*r; clrscr(); printf(“Area = %g”, area); } OUTPUT: Area=12.56; www.eshikshak.co.in
  • 19. Example : Type Modifiers void main() { short t = 1; • The keywords signed, long k = 54111; unsigned u = 10; unsigned, short and signed j = -10; long are type modifiers. clrscr(); • A type modifier printf(“n t=%d”,t) changes the meaning of printf(“n k=%ld”, k); basic data type and printf(“n u=%u, u); printf(“n j=%d”, j); produces a new type. } • Each of these type OUTPUT modifiers is applicable t = 1; k = 54111; to the basic data type u = 10; int. j = -10 www.eshikshak.co.in
  • 20. • Type Conversion • Wrapping Around • Constant and Volatile Variables www.eshikshak.co.in