Understanding Different Types of Constants in Programming

Slide Note
Embed
Share

Constants in programming are fixed values that do not change during program execution. They include character, numerical, and string constants. Integer constants can be decimal, octal, or hexadecimal. This article explains each type of constant with examples of decimal, octal, and hexadecimal integers, as well as real constants represented in decimal notation and exponential notation.


Uploaded on Sep 13, 2024 | 0 Views


Download Presentation

Please find below an Image/Link to download the presentation.

The content on the website is provided AS IS for your information and personal use only. It may not be sold, licensed, or shared on other websites without obtaining consent from the author. Download presentation by click this link. If you encounter any issues during the download, it is possible that the publisher has removed the file from their server.

E N D

Presentation Transcript


  1. CONSTANTS Mr.M.Sulthan Ibrahim Associate Professor of Computer Science Hajee Karutha Rowther Howdia College(Autonomous)

  2. CONSTANTS Constants in C refer to fixed values that do not change during the execution of a program

  3. TYPES OF CONSTANTS CONSTANTS Character constant Numerical constant Single character constants Integer constant Real constant string constant

  4. Integer constants An integer constant refers to a sequence of digits. There are three types of integers 1. decimal integer. 2. octal integer. 3. hexadecimal integer

  5. Decimal integers Decimal integers consist of a set of digits, 0 through 9, preceded by an optional or + sign Examples. 123 -321 0 654321 +78

  6. Octal integers Octal integers consist of any combination of digits from the set 0 through 7, with a leading 0. Examples 037 0 0435 0551

  7. Decimal to octal convertion 291 8 8 36 3 4 4 Decimal octal 291 = 0443

  8. Hexadecimal integer A sequence of digits preceded by 0x or 0X is considered as hexadecimal integer. They may also include alphabets A through F or a through f. the letter A through F represent the numbers 10 through 15 Examples 0X2 0x9F 0Xbcd 0x

  9. Decimal to Hexadecimal convertion 16 16 498 31 2 15 1 Decimal hexadecimal 498 = 0X1f2 or 0x1f2

  10. Real constants Numbers containing fractional parts are called real constant or floating point constant (17.543) Real constants are represented in two ways 1. Decimal notation. 2. Exponential or Scientific notation

  11. Decimal notation A whole number followed by decimal point and fractional part is called real constant in decimal notation. Examples 0.00083 -0.75 435.36 +247.0 215. .95

  12. Exponential or Scientific notation A real number may also expressed in exponential notation Example the value 215.65 may be written as 2.1565e2 in exponential notation. Here e2 means multiply by 102

  13. = 2.1565 X 102 215.65 215.65 = 2.1565e2 = 4.51X 10-5= 4.51E-5 0.0000451 6510000000 = 6.51 X 109= 6.51E9

  14. The general form is: mantissa e exponent 2.156 e 2 The mantissa is a real number expressed in decimal notation. The exponent is an integer number with an optional plus or minus sign. The letter e separate the mantissa and the exponent can be written in either lowercase or uppercase.

  15. Single character constants A single character constant contains a single character enclosed within a pair of single quote mark Example x 5 ; Note: the character constant 5 is not the same as the number 5. Character constant have integer values known as ASCII values

  16. String Constants A string constant is a sequence of character enclosed in double quotes. The characters may be letters numbers, special characters and blank space Example Hello 2002 Well Done ?...! 5+3 x Note: A character constant(e.g., x ) is not equivalent to the single character string constant(e.g., x )

  17. Backslash Character Constant C support some special backslash character constants that are used in output function. For example, the symbol \n stands for newline character. Note: each one of them represents one character, although they consist of two characters. These characters combinations are known as escape sequences.

  18. constant meaning \a \b \f \n \r \t \v \ \ \? \\ \0 Audible alert(bell) Back space Form feed New line Carriage return Horizontal tab Vertical tab Single quote Double quote Question mark Backslash null

  19. Variables A variable is a data name that may be used to store a data value. A variable may take different value at different times during execution.

  20. A variable name can be chosen in a meaning full way so as to reflect its function or nature in the program. Examples average height total counter_1 class_strenth

  21. Variable names may consist of lettes,digits, and underscore character, subject to the following conditions. 1. They must begin with a letter. 2. ANSI standard recognizes a length of 31 characters. However, length should not be normally more than eight characters.

  22. 3. Uppercase and lowercase are significant. This is, the variable Total is not the same as total or TOTAL 4. It should not be a keyword. 5. White space is not allowed.

Related