.

C Programming Constants Assignment Help

Constants

Constants in C are the fixed values that are used in a program, and its value cannot be changed during the entire execution of the program. Constants otherwise called as literals. There are 3 primary types of constants such as,

  1. Numeric Constants
    • Integer Constants
    • Real Constants
  2. Character Constants
    • Single Character Constants
    • String Constants

C Programming Datatypes Assignment Help By Online Tutoring and Guided Sessions from assignmenthippo.com


Numeric Constants

Integer Constants

This type of constant is further classified into:

  • Decimal Integer
  • Octal Integer
  • Hexadecimal Integer

Example

20, 0, -200, +40, 0X6

Real Constants

Constants that contain decimal point are real constants. 

Example

0.5, 0.0034, 34.45

Character Constants

Character constant represents single character is enclosed a pair of single quote (‘ ‘ ). It contains set of integer values known as ASCII values (American Standard Code for Information Interchange). 

Character constant ‘5’ is not equivalent to 5, moreover it represents the ASCII value 53.

Some Character constant and associated ASCII values are-

Character ASCII Values

A – Z         65 - 90

a – z         97 – 122

0 – 9         48 – 57

; 59

Some valid character constants are-

‘9’ , ‘M’, ‘3’, ‘#’

String Constants

String consists zero, one or more characters. A string constant represented by a pair of double quotes (“ “). 

Example

“Hello”, “Welcome to Lab”

Defining Constants

Constants are defined in two ways-

  • Using #define preprocessor directive
  • Using const keyword

Rules to define constants

#define identifierName value

const datatype identifiername=value

Example

#define pi 3.14

cons int a=5

.